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>
#include "traffic.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e6 + 2;
const ll linf = 1e18;
vector<int> g[N];
int sz[N];
void Dfs(int s, int e) {
for (int u : g[s]) {
if (u == e) continue;
Dfs(u, s);
sz[s] += sz[u];
}
}
int Dfs1(int s, int e, int o) {
for (int u : g[s]) {
if (u == e) continue;
if (2 * sz[u] > o) return Dfs1(u, s, o);
}
return s;
}
int LocateCentre(int n, int p[], int u[], int v[]) {
for (int i = 0; i < n - 1; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
for (int i = 0; i < n; i++) sz[i] = p[i];
Dfs(0, -1);
return Dfs1(0, -1, sz[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... |