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>
#define fi first
#define se second
#define rep(a, b) for(int a = 0; a < (int)(b); a++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
vi graf[N];
int pod[N],t[N];
ll res=LLONG_MAX;
int g;
void dfs(int v,int o){
pod[v]+=t[v];
for(auto u:graf[v]){
if(u==o) continue;
dfs(u,v);
pod[v]+=pod[u];
}
}
void dfs2(int v,int o,int nad){
if(res>pod[v]+nad) res=pod[v]+nad,g=v;
for(auto u:graf[v]){
if(u==o) continue;
dfs2(u,v,pod[v]-pod[u]);
}
}
int LocateCentre(int n,int p[],int s[],int d[]){
rep(i,n-1) graf[s[i]].push_back(d[i]),graf[d[i]].push_back(s[i]);
rep(i,n) t[i]=p[i];
dfs(0,0);
dfs2(0,0,0);
return g;
}
# | 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... |