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 <bits/stdc++.h>
std::vector <std::vector <int>> g;
std::vector <int> ans, sms;
int sum = 0;
void dfs(int val[], int node = 0, int par = -1) {
sms[node] = val[node];
for (int x : g[node]) if (x != par) {
dfs(val, x, node);
sms[node] += sms[x];
ans[node] = std::max(ans[node], sms[x]);
}
ans[node] = std::max(ans[node], sum - sms[node]);
}
int LocateCentre(int n, int val[], int u[], int v[]) {
for (int i = 0; i < n; i++) sum += val[i];
g.resize(n);
ans.resize(n, 0);
sms.resize(n, 0);
for (int i = 0; i < n - 1; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(val);
int ansind = 0, best = INT_MAX;
for (int i = 0; i < n; i++) {
if (ans[i] < best) {
best = ans[i];
ansind = i;
}
}
return ansind;
}
# | 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... |