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>
#define ll long long
using namespace std;
ll mx,pr[1000005],sum[1000005],s;
int loc;
vector<int> v[1000005];
void dfs(int a,int p){
ll mx=0;
for(int i:v[a]){
if(i==p) continue;
dfs(i,a);
sum[a]+=sum[i];
mx=max(mx,sum[i]);
}
pr[a]=mx;
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
mx=1e18;
loc=-1;
for(int i=0;i<N;i++){
sum[i]=pp[i];
s+=pp[i];
}
for(int i=0;i<N-1;i++){
v[S[i]].push_back(D[i]);
v[D[i]].push_back(S[i]);
}
dfs(0,-1);
for(int i=0;i<N;i++){
pr[i]=max(pr[i],s-sum[i]);
if(pr[i]<mx){
mx=pr[i];
loc=i;
}
}
return loc;
}
# | 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... |