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;
#define ff first
#define ss second
#define pb push_back
const int N=3e6+5;
vector<int>v[N];
int k=0;
int w[N];
int P[N];
int ans=INT_MAX;
int x=-1;
void fun(int a,int p){
int h=0;
for(auto b:v[a]){
if(b==p)continue;
fun(b,a);
w[a]+=w[b];
}
for(auto b:v[a]){
if(b==p)continue;
h=max(h,w[b]);
}
w[a]+=P[a];
h=max(h,k-w[a]);
if(ans>h){
ans=h;
x=a;
}
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
int n=N;
for(int i=0;i<n;i++){
w[i]=0;
P[i]=pp[i];
}
for(int i=0;i<n-1;i++){
v[S[i]].pb(D[i]);
v[D[i]].pb(S[i]);
}
for(int i=0;i<n;i++){
k+=pp[i];
}
fun(0,-1);
return x;
}
# | 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... |