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 ii pair<int, int>
using namespace std;
vector<int> adj[1000001];
int dp[1000001];
ii ans = make_pair(INT_MAX, -1);
int dfs(int a, int p){
for(auto x : adj[a]){
if(x == p) continue;
dp[a] += dfs(x, a);
}
return dp[a];
}
int dfs2(int a, int p, int s){
int tmp = s;
for(auto x : adj[a]){
if(x == p) continue;
tmp = max(tmp, dp[x]);
dfs2(x, a, s + dp[a] - dp[x]);
}
if(tmp < ans.first) ans = make_pair(tmp, a);
}
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]);
dp[i] = P[i];
}
dp[N - 1] = P[N - 1];
dfs(0, -1);
dfs2(0, -1, 0);
return ans.second;
}
Compilation message (stderr)
traffic.cpp: In function 'int dfs2(int, int, int)':
traffic.cpp:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
24 | }
| ^
# | 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... |