# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
805288 | QwertyPi | 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 "traffic.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 11;
int p[N], sz[N];
vector<int> G[N];
void dfs(int v, int par = -1){
for(auto i : G[v]){
if(i != par){
dfs(i, v);
sz[v] += sz[i];
}
}
sz[v] += p[v];
}
void centroid(int v, int par = -1){
for(auto i : G[v]){
if(i != par && sz[i] >= (sz[0] + 1) / 2){
centroid(i, v);
return;
}
}
cout << v << endl;
return;
}
int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++){
cin >> p[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);
}
dfs(0);
centroid(0);
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
for(int i = 0; i < N - 1; i++){
G[S[i]].push_back(D[i]);
G[D[i]].push_back(S[i]);
}
dfs(0); return centroid(0);
}