# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
491574 | vendx_greyback | Traffic (IOI10_traffic) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int,int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
const int mxn = 1e6;
vi adj[mxn];
int sz[mxn];
int mx[mxn];
void dfs(int u, int p){
for(auto v: adj[u]){
if(v == p)
continue;
dfs(v, u);
sz[u] += sz[v];
mx[u] = max(mx[u], sz[v]);
}
}
int LocateCentre(int n, int p[], int s[], int d[]){
for(int i = 0; i < n-1; i++){
adj[s[i]].push_back(d[i]);
adj[d[i]].push_back(s[i]);
}
int total = 0;
for(int i = 0; i < n; i++){
sz[i] = p[i];
total += p[i];
}
dfs(0, -1);
int wt = 1e18;
int res = -1;
for(int i = 0; i < n; i++){
int temp = max(mx[i], total - sz[i]);
if(temp < wt){
wt = temp;
res = i;
}
}
return res;
}