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"
using namespace std;
typedef long long ll;
int LocateCentre(int n,int x[],int va[],int vb[])
{
vector<int> v[n];
for(int i=0;i<n-1;i++)
{
v[va[i]].push_back(vb[i]);
v[vb[i]].push_back(va[i]);
}
int sum=0;
for(int i=0;i<n;i++) sum+=x[i];
vector<int> s(n,0);
array<int,2> res={2000000001,0};
function<void(int,int)> dfs=[&](int a,int p)
{
s[a]=x[a];
int mx=0;
for(int to:v[a])
{
if(to==p) continue;
dfs(to,a);
s[a]+=s[to];
mx=max(mx,s[to]);
}
mx=max(mx,sum-s[a]);
res=min(res,{mx,a});
};
dfs(0,-1);
return res[1];
}
# | 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... |