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];
}
int centroid(int v, int par = -1){
for(auto i : G[v]){
if(i != par && sz[i] >= (sz[0] + 1) / 2){
return centroid(i, v);
}
}
return v;
}
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);
}
# | 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... |