제출 #481620

#제출 시각아이디문제언어결과실행 시간메모리
481620SlavicGTraffic (IOI10_traffic)C++17
100 / 100
920 ms184044 KiB
#include "traffic.h" #include "bits/stdc++.h" using namespace std; #define ll long long #define forn(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define sz(a) (int)a.size() const int N = 1e6 + 10; vector<int> adj[N]; ll ss[N]; ll mx[N]; ll x[N]; void dfs(int u, int par){ ss[u] = x[u]; for(int v: adj[u]){ if(v == par)continue; dfs(v, u); ss[u] += ss[v]; mx[u] = max(mx[u], ss[v]); } } int LocateCentre(int n, int p[], int s[], int d[]){ for(int i = 0;i < n - 1;++i){ int u = s[i], v = d[i]; adj[u].pb(v); adj[v].pb(u); } for(int i = 0;i < n;++i){ x[i] = p[i]; } dfs(0, -1); ll ans = mx[0]; int idx = 0; for(int i = 1;i < n;++i){ if(ans > max(mx[i], ss[0] - ss[i])){ ans = max(mx[i], ss[0] - ss[i]); idx = i; } } return idx; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...