Submission #503204

#TimeUsernameProblemLanguageResultExecution timeMemory
503204Hacv16Traffic (IOI10_traffic)C++17
100 / 100
1010 ms156624 KiB
#include<bits/stdc++.h> #include "traffic.h" using namespace std; const int MAX = 1e6 + 15; const int INF = 0x3f3f3f3f; #define pb push_back #define sz(x) (int) x.size() #define fr first #define sc second #define mp make_pair #define all(x) x.begin(), x.end() int fans = 0; vector<int> adj[MAX], child(MAX), cong(MAX), fan(MAX); void dfs(int x, int p){ for(auto v : adj[x]){ if(v == p) continue; dfs(v, x); child[x] += child[v]; cong[x] = max(cong[x], child[v]); } cong[x] = max(cong[x], fans - child[x] - fan[x]); child[x] += fan[x]; } int LocateCentre(int n, int p[], int s[], int d[]){ for(int i = 0; i < n; i++){ fans += p[i]; fan[i] = p[i]; } for(int i = 0; i < n - 1; i++){ adj[s[i]].pb(d[i]); adj[d[i]].pb(s[i]); } dfs(0, -1); int id = -1, sm = INF; for(int i = 0; i < n; i++){ if(cong[i] < sm){ id = i, sm = cong[i]; } } return id; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...