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 "traffic.h"
#include <vector>
using namespace std;
const int MAXN = 1e6 + 3e2;
vector<int> g[MAXN];
int cnt[MAXN];
void dfs(int v, int p){
for (int u : g[v]){
if (u != p){
dfs(u, v);
cnt[v] += cnt[u];
}
}
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
for (int i = 0; i < N; i++) cnt[i] = pp[i];
for (int i = 0; i < N - 1; i++){
g[S[i]].push_back(D[i]);
g[D[i]].push_back(S[i]);
}
dfs(0, 0);
int mn = 2e9 + 5, ans = 0;
for (int i = 0; i < N; i++){
int cur = cnt[0] - cnt[i];
for (int j : g[i]){
if (cnt[j] < cnt[i]) cur = max(cur, cnt[j]);
}
if (cur < mn) mn = cur, ans = i;
}
return ans;
}
# | 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... |