Submission #738628

#TimeUsernameProblemLanguageResultExecution timeMemory
738628ToxtaqTraffic (IOI10_traffic)C++17
0 / 100
0 ms212 KiB
#include<bits/stdc++.h> //#include "traffic.h" using namespace std; vector<vector<int>>g; vector<long long>fans; vector<long long>sub, res; void calc(int node, int par){ sub[node] = fans[node]; for(int v : g[node]){ if(v != par){ calc(v, node); sub[node] += sub[v]; } } } void traverse(int node, int par){ res[node] = max(res[node], sub[par] - sub[node]); for(int v : g[node]){ if(v == par)continue; res[node] = max(sub[v], res[node]); } for(int v : g[node]){ if(v != par){ traverse(v, node); } } } int LocateCentre(int n, int p[], int s[], int d[]){ g.resize(n); fans.resize(n); res.resize(n); sub.resize(n); for(int i = 0;i < n - 1;++i){ g[s[i]].push_back(d[i]); g[d[i]].push_back(s[i]); } for(int i = 0;i < n;++i){ fans[i] = p[i]; } calc(1, 1); traverse(1, 1); int mn = 1e9, id = -1; for(int i = 0;i < n;++i){ if(mn > res[i]){ mn = res[i]; id = i; } } return id; } //int main() //{ // int n; // cin >> n; // g.resize(n); // fans.resize(n); // res.resize(n); // sub.resize(n); // for(int i = 0;i < n;++i){ // cin >> fans[i]; // } // for(int i = 0;i < n - 1;++i){ // int u, v; // cin >> u >> v; // g[u].push_back(v); // g[v].push_back(u); // } // // calc(1, 1); // traverse(1, 1); // int mn = 1e9, id = -1; // for(int i = 0;i < n;++i){ // if(mn > res[i]){ // mn = res[i]; // id = i; // } // } // cout << 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...