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 <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1e6 + 1;
vector <int> adj[MAX];
ll sum[MAX];
int pars[MAX];
void dfs(int u, int par, int p[])
{
sum[u] = p[u];
pars[u] = par;
for (int v : adj[u])
if (v != par)
dfs(v, u, p);
for (int v : adj[u])
if (v != par)
sum[u] += sum[v];
}
int LocateCentre(int n, int p[], int s[], int d[])
{
for (int i = 0; i < n - 1; ++i)
{
adj[s[i]].emplace_back(d[i]);
adj[d[i]].emplace_back(s[i]);
}
dfs(0, 0, p);
pair <ll, int> ans = make_pair(LLONG_MAX, -1);
for (int u = 0; u < n; ++u)
{
ll m = -1, cur = p[u];
for (int v : adj[u])
{
if (v != pars[u])
{
m = max(m, sum[u]);
cur += p[v];
}
}
if (u) m = max(m, sum[0] - cur);
ans = min(ans, make_pair(m, u));
}
cout << ans.second << '\n';
}
Compilation message (stderr)
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:48:1: warning: no return statement in function returning non-void [-Wreturn-type]
48 | }
| ^
# | 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... |