# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
991112 | borisAngelov | Traffic (IOI10_traffic) | C++17 | 821 ms | 198096 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.
#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
const long long inf = (1LL << 62);
int n;
int a[maxn];
vector<int> g[maxn];
long long subtreeSum[maxn];
long long down[maxn];
long long prv[maxn];
long long ans[maxn];
void dfsInit(int node, int par)
{
subtreeSum[node] = a[node];
down[node] = 0;
for (int i = 0; i < g[node].size(); ++i)
{
if (g[node][i] != par)
{
dfsInit(g[node][i], node);
subtreeSum[node] += subtreeSum[g[node][i]];
down[node] = max(down[node], subtreeSum[g[node][i]]);
}
}
prv[node] = down[node];
}
void dfsSolve(int node, int par)
{
ans[node] = down[node];
for (int i = 0; i < g[node].size(); ++i)
{
int to = g[node][i];
if (to != par)
{
subtreeSum[node] -= subtreeSum[to];
subtreeSum[to] += subtreeSum[node];
down[to] = max(down[to], subtreeSum[node]);
dfsSolve(to, node);
down[to] = prv[to];
subtreeSum[to] -= subtreeSum[node];
subtreeSum[node] += subtreeSum[to];
}
}
}
int LocateCentre(int N, int pp[], int S[], int D[])
{
n = N;
for (int i = 1; i <= n; ++i)
{
a[i] = pp[i - 1];
}
for (int i = 1; i <= n - 1; ++i)
{
int x = S[i - 1];
int y = D[i - 1];
++x;
++y;
g[x].push_back(y);
g[y].push_back(x);
}
dfsInit(1, -1);
dfsSolve(1, -1);
long long big = inf;
int node = -1;
for (int i = 1; i <= n; ++i)
{
//cout << i << " :: " << ans[i] << endl;
if (big > ans[i])
{
big = ans[i];
node = i;
}
}
//cout << big << endl;
return node - 1;
}
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... |