# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393371 | huukhang | Traffic (IOI10_traffic) | C++11 | 1208 ms | 156788 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// - Only when necessary :d
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
int sum = 0;
int a[1000005];
vector<vector<int>> g;
int sz[1000005], congest[1000005];
void dfs(int s, int p) {
sz[s] = a[s];
for (auto v : g[s]) {
if (v != p) {
dfs(v, s);
sz[s] += sz[v];
congest[s] = max(congest[s], sz[v]);
}
}
congest[s] = max(congest[s], sum - sz[s]);
}
int LocateCentre(int n, int p[], int s[], int d[]) {
for (int i = 0; i < n; ++i) a[i] = p[i];
g.resize(n);
for (int i = 0; i < n - 1; ++i) {
g[s[i]].push_back(d[i]);
g[d[i]].push_back(s[i]);
}
for (int i = 0; i < n; ++i) sum += a[i];
dfs(0, -1);
int mn = inf, ans;
for (int i = 0; i < n; ++i) {
if (mn > congest[i]) {
mn = congest[i];
ans = i;
}
}
return ans;
}
Compilation message (stderr)
# | 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... |