Submission #638418

#TimeUsernameProblemLanguageResultExecution timeMemory
638418ojoConmigoTraffic (IOI10_traffic)C++17
0 / 100
1 ms212 KiB
#include "traffic.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> g; vector<long long> fir,sec,ans,subarbol; void dfs1(int nodo, int p, int pp[]){ for(int v : g[nodo]){ if(v == p)continue; dfs1(v,nodo,pp); subarbol[nodo] += subarbol[v] + pp[v]; if(subarbol[v] + pp[v] > fir[nodo]){ sec[nodo] = fir[nodo]; fir[nodo] = subarbol[v] + pp[v]; }else if(subarbol[v] + pp[v] > sec[nodo]){ sec[nodo] = subarbol[v] + pp[v]; } } //cout << nodo << " " << fir[nodo] << " " << sec[nodo] << endl; } void dfs2(int nodo, int p, long long cont, int pp[]){ ans[nodo] = max(cont,fir[nodo]); for(int v : g[nodo]){ if(v == p)continue; if(subarbol[v] + pp[v] == fir[nodo]) dfs2(v,nodo,(cont > sec[nodo] ? cont + subarbol[nodo] - subarbol[v] : sec[nodo] + pp[nodo]),pp); else dfs2(v,nodo,cont + subarbol[nodo] - subarbol[v], pp); } } int LocateCentre(int N, int pp[], int S[], int D[]) { g.resize(N); for(int i=0; i<N-1; i++){ int x,y; x = S[i]; y = D[i]; //cout << x << " " << y << endl; g[x].push_back(y); g[y].push_back(x); } fir.assign(N,0); sec.assign(N,0); subarbol.assign(N,0); ans.resize(N); dfs1(0,-1,pp); dfs2(0,-1,0,pp); int arena = 0; long long congestion = 2e9 + 1; for(int i=0; i<N; i++){ //cout << i << " " << ans[i] << " " << congestion << endl; if(ans[i] < congestion){ congestion = ans[i]; arena = i; } } //cout << arena << endl; return arena; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...