Submission #513449

#TimeUsernameProblemLanguageResultExecution timeMemory
513449PoPularPlusPlusTraffic (IOI10_traffic)C++17
100 / 100
907 ms141504 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb(e) push_back(e) #define sv(a) sort(a.begin(),a.end()) #define sa(a,n) sort(a,a+n) #define mp(a,b) make_pair(a,b) #define vf first #define vs second #define ar array #define all(x) x.begin(),x.end() const int inf = 0x3f3f3f3f; const int mod = 1000000007; const double PI=3.14159265358979323846264338327950288419716939937510582097494459230; bool remender(ll a , ll b){return a%b;} #include "traffic.h" const int N = 1000003; vector<int> adj[N]; int ans[N]; int p[N]; int sum[N]; void dfs(int node){ ans[node] = 0; sum[node] = p[node]; for(int i : adj[node]){ if(ans[i] == -1){ dfs(i); ans[node] = max(ans[node] , sum[i]); sum[node] += sum[i]; } } } int LocateCentre(int n, int pp[], int s[], int d[]){ int su = 0; for(int i = 0; i < n - 1; i++){ adj[s[i]].pb(d[i]); adj[d[i]].pb(s[i]); p[i] = pp[i]; su += pp[i]; } p[n-1] = pp[n-1]; su += pp[n-1]; memset(ans,-1,sizeof ans); dfs(0); int res = 2000000000; int pos = -1; for(int i = 0; i < n; i++){ res = min(res , max(ans[i] , su - sum[i])); if(res == max(ans[i] , su - sum[i]))pos = i; //cout << ans[i] << ' ' << sum - (ans[i] + p[i]) << '\n'; } return pos; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...