Submission #632254

#TimeUsernameProblemLanguageResultExecution timeMemory
632254deviceTraffic (IOI10_traffic)C++17
100 / 100
1136 ms170664 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[1000000], ans, mn = INT_MAX; vector<int> adj[1000000]; void init(int cur, int par = -1){ for(int nxt:adj[cur]){ if(nxt == par) continue; init(nxt, cur); a[cur] += a[nxt]; } } void dfs(int cur, ll val = 0, int par = -1){ ll mx = val; for(int nxt:adj[cur]){ if(nxt == par) continue; mx = max(mx, a[nxt]); dfs(nxt, val + a[cur] - a[nxt], cur); } if(mx < mn){ mn = mx; ans = cur; } } int LocateCentre(int n, int p[], int s[], int d[]){ for(int i = 0; i < n; i++) a[i] = p[i]; for(int i = 0; i < n-1; i++){ adj[s[i]].push_back(d[i]); adj[d[i]].push_back(s[i]); } init(0); dfs(0); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...