Submission #312159

#TimeUsernameProblemLanguageResultExecution timeMemory
312159AmineTrabelsiTraffic (IOI10_traffic)C++14
0 / 100
19 ms24064 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; #define pb push_back #define mp make_pair #define f first #define s second #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() // Hi const int M = 1e6; vector<int> gr[M]; int *people; ll sum[M]; void dfs(int i,int par){ sum[i] = people[i]; for(auto u:gr[i]){ if(u!=par){ dfs(u,i); sum[i]+=sum[u]; } } } ll LocateCentre(int n,int p[],int ff[],int d[]){ ll ss = p[n-1]; for(int i=0;i<n-1;i++){ ss += p[i]; gr[ff[i]].pb(d[i]); gr[d[i]].pb(ff[i]); } people = p; dfs(1,1); ll res = 1e18; int city = 0; for(int i=0;i<n;i++){ ll x = max(ss-sum[i],sum[i]-p[i]); if(x < res){ city = i; res = x; } } return city; } /* int main(){ int p[5] = {10,10,10,10,50},s[4] = {1,2,3,4},d[4] = {0,0,0,0}; cout<<LocateCentre(5,p,s,d)<<'\n'; return 0; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...