Submission #1051629

#TimeUsernameProblemLanguageResultExecution timeMemory
1051629Nika533Race (IOI11_race)C++17
9 / 100
221 ms70052 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define s second using namespace std; const int N=2e5+5; int n,k,ans=1e9; int depth[N]; long long d[N]; vector<pair<int,int>> g[N]; map<pair<int,int>,int> edge; map<long long,int> mymap[N]; void dfs(int x, int p) { d[x]=d[p]+edge[{x,p}]; depth[x]=depth[p]+1; mymap[x][d[x]]=depth[x]; for (auto A:g[x]) { int y=A.f,w=A.s; if (y==p) continue; dfs(y,x); int sx=mymap[x].size(),sy=mymap[y].size(); if (sx<sy) swap(mymap[x],mymap[y]); for (auto AA:mymap[y]) { long long D=AA.f; int DEPTH=AA.s; if (mymap[x][k+2*d[x]-D]>0) { int val=mymap[x][k+2*d[x]-D]+DEPTH-2*depth[x]; ans=min(ans,val); } } for (auto AA:mymap[y]) { long long D=AA.f; int DEPTH=AA.s; if (mymap[x][D]==0) mymap[x][D]=DEPTH; else mymap[x][D]=min(mymap[x][D],DEPTH); } } } int best_path(int N, int K, int H[][2], int L[]) { n=N; k=K; for (int i=0; i<n-1; i++) { int a=H[i][1],b=H[i][0],c=L[i]; g[a].pb({b,c}); g[b].pb({a,c}); edge[{a,b}]=edge[{b,a}]=c; } dfs(0,0); if (ans==1000000000) ans=-1; return ans; }

Compilation message (stderr)

race.cpp: In function 'void dfs(int, int)':
race.cpp:20:19: warning: unused variable 'w' [-Wunused-variable]
   20 |         int y=A.f,w=A.s;
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...