#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[1000006], C[1000006] , tot;
vector <int> adj[1000005];
void dfs(int v,int p) {
dp[v] = 0;
int s = 0;
int r = 0;
for (int i:adj[v]) {
if (i != p) {
dfs (i,v);
dp[v] = max(dp[v], dp[i] + C[i]);
}
}
}
int LocateCentre(int n,int P[],int S[],int D[]) {
for (int i = 0; i < n-1; i++)
adj[S[i]].push_back(D[i]),
adj[D[i]].push_back(S[i]),
C[i] = P[i], tot += C[i];
C[n-1] = P[n-1];
pair<int,int> ans = {INT_MAX,-1};
for (int i = 0; i < n; i++) {
dfs(i,-1);
ans = min(ans,{dp[i],i});
}
return ans.second;
} /*
int main(){
static int N,P[1000000],S[1000000],D[1000000];
int i;
scanf("%d",&N);
for (i=0;i<N;i++) scanf("%d",&P[i]);
for (i=0;i<N-1;i++) scanf("%d%d",&S[i],&D[i]);
int r = LocateCentre(N,P,S,D);
printf("%d\n",r);
return 0;
} */
Compilation message
traffic.cpp: In function 'void dfs(long long int, long long int)':
traffic.cpp:8:6: warning: unused variable 's' [-Wunused-variable]
int s = 0;
^
traffic.cpp:9:6: warning: unused variable 'r' [-Wunused-variable]
int r = 0;
^
traffic.cpp: In function 'long long int LocateCentre(long long int, long long int*, long long int*, long long int*)':
traffic.cpp:19:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (int i = 0; i < n-1; i++)
^~~
traffic.cpp:23:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
C[n-1] = P[n-1];
^
/tmp/ccLvr3y7.o: In function `main':
grader.cpp:(.text.startup+0xb1): undefined reference to `LocateCentre(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status