(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 #335455

#TimeUsernameProblemLanguageResultExecution timeMemory
335455gozoniteTraffic (IOI10_traffic)C++14
100 / 100
1378 ms186452 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<pair<int, int>> vii; typedef pair<int, int> pi; vector<int> adj[1000000]; ll p[1000000]; ll sub[1000000]; ll res; ll mt[1000000]; void dfs(int u, int par, ll pc) { ll tsum = 0, mv = 0; for (auto v : adj[u]) { if (v == par) continue; tsum += sub[v]; mv = max(mv, sub[v]); } mt[u] = max(mv, pc); for (auto v : adj[u]) { if (v == par) continue; dfs(v, u, pc+tsum-sub[v]+p[u]); } } ll gsum(int u, int par) { ll tsum = p[u]; for (auto v : adj[u]) { if (v == par) continue; tsum += gsum(v, u); } sub[u] = tsum; return sub[u]; } int LocateCentre(int N, int P[], int S[], int D[]) { for (int i = 0; i < N; i++) adj[i].clear(); for (int i = 0; i < N; i++) p[i] = P[i]; res = 1e18; //fill(mt, mt+N, 0); for (int i = 0; i < N-1; i++) { int a = S[i], b = D[i]; adj[a].push_back(b); adj[b].push_back(a); } gsum(0, -1); dfs(0, -1, 0); //cout << "Debugging array" << endl; //for (int i = 0; i < N; i++) cout << mt[i] << " "; cout << endl; //for (int i = 0; i < N; i++) cout << sub[i] << " "; cout << endl; int mi = 0; for (int i = 1; i < N; i++) { if (mt[i] < mt[mi]) mi = i; } return mi; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...