Submission #957073

#TimeUsernameProblemLanguageResultExecution timeMemory
957073MuntherCarrotTraffic (IOI10_traffic)C++14
100 / 100
794 ms184192 KiB
#include <bits/stdc++.h> #include "traffic.h" using namespace std; #define ll long long const int MAXN = 1e6 + 10; vector<vector<int>> vtx(MAXN); ll a[MAXN], mx[MAXN], son[MAXN]; ll all; void dfs(int u, int p){ for(int v : vtx[u]){ if(v == p) continue; dfs(v, u); mx[u] = max(mx[u], son[v]); son[u] += son[v]; } son[u] += a[u]; mx[u] = max(mx[u], all - son[u]); } int LocateCentre(int N, int P[], int S[], int D[]){ all = accumulate(P, P + N, 0ll); for(int i = 0; i < N; i++){ a[i] = P[i]; } for(int i = 0; i < N - 1; i++){ vtx[S[i]].push_back(D[i]); vtx[D[i]].push_back(S[i]); } dfs(0, 0); int ans = 0; for(int i = 1; i < N; i++){ if(mx[i] < mx[ans]){ ans = i; } } return ans; } // by me
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...