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+10;
int n, a[N], sz[N];
vector<int> g[N];
void dfs_sz(int u, int p){
sz[u]=a[u];
for (int v:g[u]) if (v!=p){
dfs_sz(v, u);
sz[u]+=sz[v];
}
}
int find_centroid(int u, int p, int s){
for (int v:g[u]) if (v!=p && sz[v]*2>s) return find_centroid(v, u, s);
return u;
}
int LocateCentre(int _N, int pp[], int S[], int D[]) {
n=_N;
for (int i=0; i<n; ++i) a[i]=pp[i];
for (int i=0; i<n-1; ++i){
g[S[i]].push_back(D[i]);
g[D[i]].push_back(S[i]);
}
dfs_sz(0, -1);
int u=find_centroid(0, -1, sz[0]);
dfs_sz(u, -1);
for (int i=0; i<n; ++i) g[i].clear();
return u;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |