#include<bits/stdc++.h>
//#include "traffic.h"
using namespace std;
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
const int maxn=1e6;
const ll INF=1e18;
vector<int>adj[maxn],used(maxn,0),par(maxn);
ll tot[maxn];
int LocateCentre(int N, int P[], int S[], int D[]) {
ll all=0;
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++){
all+=P[i];
}
function <void(int)> dfs=[&](int x){
used[x]=1;
tot[x]+=(ll)P[x];
for(auto y:adj[x]){
if(used[y]==0){
par[y]=x;
dfs(y);
tot[x]+=(ll)P[y];
}
}
};
function <ll(int,int)> num=[&](int x,int y){
if(par[y]==x){
return tot[y];
}
else{
return all-tot[x];
}
};
dfs(0);
par[0]=-1;
ll mn=INF;
int ans=0;
for(int i=0;i<N;i++){
ll cur=0;
for(auto y:adj[i]){
cur=max(cur,num(i,y));
}
cout<<i<<' '<<cur<<"\n";
if(cur<mn){
mn=cur;
ans=i;
}
}
return ans;
}
int main(){
int P[5]={10,10,10,20,20},S[4]={0,1,2,3},D[4]={2,2,3,4};
cout<<LocateCentre(5,P,S,D);
}
Compilation message
/usr/bin/ld: /tmp/ccouFEdz.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccw6iLuB.o:traffic.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status