# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666206 | sofija6 | Traffic (IOI10_traffic) | C++14 | 1034 ms | 170808 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 <bits/stdc++.h>
#include "traffic.h"
#define ll long long
#define MAXN 1000010
using namespace std;
vector<ll> G[MAXN];
ll dp[MAXN],par[MAXN],num[MAXN];
void DFS(ll i)
{
dp[i]=num[i];
for (ll next : G[i])
{
if (next!=par[i])
{
par[next]=i;
DFS(next);
dp[i]+=dp[next];
}
}
}
int LocateCentre(int N, int pp[], int S[], int D[])
{
for (ll i=0;i<N;i++)
num[i]=pp[i];
for (ll i=0;i<N-1;i++)
{
G[S[i]].push_back(D[i]);
G[D[i]].push_back(S[i]);
}
par[0]=-1;
DFS(0);
ll ans=LLONG_MAX;
int ind;
for (ll i=0;i<N;i++)
{
ll cur=0;
for (ll next : G[i])
{
if (next==par[i])
cur=max(cur,dp[0]-dp[i]);
else
cur=max(cur,dp[next]);
}
if (cur<ans)
{
ans=cur;
ind=i;
}
}
return ind;
}
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... |