Submission #1012975

#TimeUsernameProblemLanguageResultExecution timeMemory
1012975huutuanTraffic (IOI10_traffic)C++14
0 / 100
6 ms29332 KiB
#include "traffic.h" #include <bits/stdc++.h> using namespace std; const int N=1e6+10; int n, a[N], sz[N]; vector<int> g[N]; void dfs_sz(int u, int p){ sz[u]=a[u]; for (int v:g[u]) if (v!=p){ dfs_sz(v, u); sz[u]+=sz[v]; } } int find_centroid(int u, int p, int s){ for (int v:g[u]) if (v!=p && sz[v]*2>s) return find_centroid(v, u, s); return u; } int LocateCentre(int _N, int pp[], int S[], int D[]) { n=_N; for (int i=0; i<n; ++i) a[i]=pp[i]; for (int i=0; i<n-1; ++i){ g[S[i]].push_back(D[i]); g[D[i]].push_back(S[i]); } dfs_sz(0, -1); int u=find_centroid(0, -1, sz[0]); dfs_sz(u, -1); for (int i=0; i<n; ++i) g[i].clear(); return u; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...