Submission #1341667

#TimeUsernameProblemLanguageResultExecution timeMemory
1341667selunelleRace (IOI11_race)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define pb push_back
vector<bool>vt;
void dfs(ll u,vector<vector<ll>>&e,map<pair<ll,ll>,ll>&mp,vector<pair<ll,ll>>&v,vector<map<ll,ll>>&v5,ll&k,ll&ans){
	if(vt[u]) return;
	vt[u]=true;
	v5[u][v[u].ff]=v[u].ss; 
	for(auto v1:e[u]){
		if(vt[v1]) continue;
		v[v1].ff=v[u].ff+mp[{u,v1}];
		v[v1].ss=v[u].ss+1;
		v5[v1][v[v1].ff]=v[v1].ss;
		dfs(v1,e,mp,v,v5,k,ans);
		for(auto jj:v5[v1]){
			ll d=jj.ff,c=jj.ss;
			if(d>k) continue;
			if(v5[u].count(k-d)) ans=min(ans,v5[u][k-d]+c);
		}
		if(v5[u].size()<v5[v1].size()) swap(v5[u],v5[v1]);
		for(auto jj:v5[v1]){
			ll d=jj.ff,c=jj.ss;
			if(v5[u].count(d)) v5[u][d]=min(v5[u][d],c);
			else v5[u][d]=c;
		}
	}
}

int best_path(int n, int k, int edges[][2], int* result) {
    vector<vector<long long>> e(n+1);
    map<pair<int,int>, long long> mp;
    for(int i=0;i<n-1;i++){
        int a = edges[i][0], b = edges[i][1], c = edges[i][2];
        e[a].push_back(b);
        e[b].push_back(a);
        mp[{a,b}] = c;
        mp[{b,a}] = c;
    }

    vector<bool> vt(n+1,false);
    vector<map<long long,long long>> v5(n+1);
    vector<pair<long long,long long>> v(n+1);
    v[1] = {0,0};
    long long ans = LLONG_MAX;

    dfs(1,e,mp,v,v5,k,ans);

    if(ans==LLONG_MAX) return -1;
    return ans;
}

Compilation message (stderr)

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:49:13: error: invalid initialization of reference of type 'std::map<std::pair<long long int, long long int>, long long int>&' from expression of type 'std::map<std::pair<int, int>, long long int>'
   49 |     dfs(1,e,mp,v,v5,k,ans);
      |             ^~
race.cpp:8:56: note: in passing argument 3 of 'void dfs(long long int, std::vector<std::vector<long long int> >&, std::map<std::pair<long long int, long long int>, long long int>&, std::vector<std::pair<long long int, long long int> >&, std::vector<std::map<long long int, long long int> >&, long long int&, long long int&)'
    8 | void dfs(ll u,vector<vector<ll>>&e,map<pair<ll,ll>,ll>&mp,vector<pair<ll,ll>>&v,vector<map<ll,ll>>&v5,ll&k,ll&ans){
      |                                    ~~~~~~~~~~~~~~~~~~~~^~