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>
using namespace std;
const int N = 1e6+5;
vector<int> neighbours[N];
int fans[N], total = 0, res = 0, traffic[N], posans[N], nums = 2e9+1;
void dfs(int u, int v) {
for (auto &x: neighbours[u]) {
if (x == v)
continue;
dfs(x, u);
traffic[u] += traffic[x];
posans[u] = max(posans[u], traffic[x]);
}
posans[u] = max(posans[u], total - traffic[u] - fans[u]);
traffic[u] += fans[u];
}
int LocateCentre(int n, int p[], int s[], int d[]) {
for (int i = 0; i < n - 1; ++i) {
neighbours[s[i]].push_back(d[i]), neighbours[d[i]].push_back(s[i]);
fans[i] = p[i], total += p[i];
}
fans[n - 1] = p[n - 1], total += p[n - 1];
dfs(0, -1);
for (int i = 0; i < n; ++i) {
if (nums > posans[i]) {
nums = posans[i];
res = i;
}
}
return res;
}
# | 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... |