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>
using namespace std;
int dp[1000006],sum[1000001], C[1000006] , tot;
vector <int> adj[1000005];
void dfs(int v,int p) {
dp[v] = sum[v] = 0;
int s = 0;
// int r = 0;
for (int i:adj[v]) {
if (i != p) {
dfs (i,v);
dp[v] = max(dp[v], sum[i] + C[i]);
sum[v] += sum[i] + C[i];
}
}
dp[v] = max(dp[v],tot - C[v] - sum[v]);
}
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]);
for (int i = 0; i < n; i++)
C[i] = P[i], tot += C[i];
pair<int,int> ans = {INT_MAX,-1};
dfs(0,-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 (stderr)
traffic.cpp: In function 'void dfs(int, int)':
traffic.cpp:7:6: warning: unused variable 's' [-Wunused-variable]
int s = 0;
^
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:20:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (int i = 0; i < n-1; i++)
^~~
traffic.cpp:23:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (int i = 0; i < n; i++)
^~~
# | 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... |