#include <iostream>
#include <bits/stdc++.h>
#define maxN 1000001
using namespace std;
vector<int> drvo[maxN];
int subtree[maxN];
int fans[maxN];
pair<int,int> ans={-1,INT_MAX};
int dfs(int v,int par)
{
int sz=fans[v];
for(int x:drvo[v])
{
if(x!=par)
{
sz+=dfs(x,v);
}
}
subtree[v]=sz;
return sz;
}
void reshi(int v,int par)
{
int lokal=0;
if(par!=-1)
{
lokal=subtree[par]-subtree[v];
}
for(int x:drvo[v])
{
if(x!=par)
{
lokal=max(lokal,subtree[x]);
}
}
if(lokal<ans.second)
{
ans.second=lokal;
ans.first=v;
}
for(int x:drvo[v])
{
if(x!=par)
{
reshi(x,v);
}
}
}
int LocateCenter(int n,int p[],int s[],int d[])
{
for(int i=0;i<n-1;i++)
{
drvo[s[i]].push_back(d[i]);
drvo[d[i]].push_back(s[i]);
}
for(int i=0;i<n;i++)
{
fans[i]=p[i];
}
dfs(0,-1);
reshi(0,-1);
return ans.first;
}
Compilation message
/tmp/cchk89KB.o: In function `main':
grader.cpp:(.text.startup+0xad): undefined reference to `LocateCentre(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status