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;
vector <int> ke[1000001];
long long sz[1000001];
void dfs(int u, int p){
for (int v:ke[u])
if (v!=p){
dfs(v,u);
sz[u]+=sz[v];
}
}
int centroid(int u, int p){
for (int v:ke[u])
if (v!=p&&sz[v]*2>sz[0])
return centroid(v,u);
return u;
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
for (int i=0;i<N-1;i++){
ke[S[i]].push_back(D[i]);
ke[D[i]].push_back(S[i]);
}
for (int i=0;i<N;i++)
sz[i]=pp[i];
dfs(0,0);
return centroid(0,0);
}
# | 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... |