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>
using namespace std;
#define sz(a) ((int)(a).size())
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef long long ll;
#ifndef wambule
// #include ".h"
#else
#endif
const int inf = 2e9;
const int N = 1000006;
int *p, a, fp = inf, fw;
vector<int> v[N];
int sgd(int x, int op) {
int z = p[x], m = 0, t;
for(int y : v[x]) {
if(y != op) {
z += (t = sgd(y, x));
m = max(m, t);
}
}
m = max(m, a - z);
if(fp > m) {
fp = m;
fw = x;
}
return z;
}
int LocateCentre(int n, int _p[], int x[], int y[]) {
p = _p;
for(int i = 0; i < n; ++i) {
a += p[i];
}
for(int i = 0; i < n - 1; ++i) {
v[x[i]].push_back(y[i]);
v[y[i]].push_back(x[i]);
}
sgd(0, -1);
return fw;
}
#ifdef wambule
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}
#endif
# | 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... |