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;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
const ll INF = 1e18;
const int mx = 1000005;
vi adj[mx];
ll sub[mx];
ll sum = 0;
pair<ll, int> ans = mp(INF, -1);
void genSub(int node, int prv = -1){
ll val = 0;
for(auto u: adj[node]){
if(u == prv) continue;
genSub(u, node);
sub[node]+=sub[u];
val = max(val, sub[u]);
}
val = max(val, sum-sub[node]);
ans = min(ans, mp(val, node));
}
int LocateCentre(int N, int P[], int S[], int D[]) {
for(int i = 0; i < N-1; i++){
adj[S[i]].pb(D[i]);
adj[D[i]].pb(S[i]);
}
for(int i = 0; i < N; i++){
sub[i]+=P[i];
sum+=P[i];
}
genSub(0);
return ans.s;
}
# | 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... |