(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #395604

#TimeUsernameProblemLanguageResultExecution timeMemory
395604garnab27Traffic (IOI10_traffic)C++17
100 / 100
1409 ms176640 KiB
#include <bits/stdc++.h> #define ll int64_t using namespace std; vector<ll > sum; vector<ll > ans; vector<int> g[1000006]; ll dfs1(int u, int p, int pp[]) { sum[u] += pp[u]; for(int v: g[u]) { if(v != p) { sum[u] += dfs1(v, u, pp); } } return sum[u]; } void dfs2(int u, int p, ll psum, int pp[]) { ans[u] = 0; ll csum = pp[u]; if(p != -1) { ans[u] = max(ans[u], psum); csum += psum; } for(int v: g[u]) { if(v != p) { csum += sum[v]; ans[u] = max(ans[u], sum[v]); } } for(int v: g[u]) { if(v != p) { dfs2(v, u, csum - sum[v], pp); } } } int LocateCentre(int N, int pp[], int S[], int D[]) { sum.resize(N); ans.resize(N); for(int i=0;i<N-1;i++) { g[S[i]].push_back(D[i]); g[D[i]].push_back(S[i]); } dfs1(0, -1, pp); dfs2(0, -1, 0, pp); int id = 0, mn = ans[0]; for(int i=1;i<N;i++) { if(mn > ans[i]) { mn = ans[i]; id = 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...