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;
int total;
vector<int> adj[1000000];
int traffic[1000000];
int acc[1000000];
int dfs(int P[], int u, int p)
{
traffic[u] = 0;
acc[u] = P[u];
for (const int &v : adj[u])
{
if (v != p)
{
acc[u] += dfs(P, v, u);
traffic[u] = max(traffic[u], acc[v]);
}
}
traffic[u] = max(traffic[u], total - acc[u]);
return acc[u];
}
int LocateCentre(int N, int P[], int S[], int D[])
{
total = 0;
for (int i = 0; i < N; i++)
total += P[i];
for (int j = 0; j < N - 1; j++)
adj[S[j]].push_back(D[j]),
adj[D[j]].push_back(S[j]);
dfs(P, 0, -1);
int city = -1;
int min_traffic = INT_MAX;
for (int i = 0; i < N; i++)
{
if (traffic[i] < min_traffic)
{
city = i;
min_traffic = traffic[i];
}
}
return city;
}
# | 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... |