# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
463496 | BT21tata | Traffic (IOI10_traffic) | C++17 | 1169 ms | 168260 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"
using namespace std;
vector<int> g[1000005];
int par[1000005], dis[1000005];
void dfs(int v, int p)
{
for(int u : g[v])
if(u!=p) par[u]=v, dfs(u, v), dis[v]+=dis[u];
}
int LocateCentre(int n, int p[], int S[], int D[])
{
int ans=2000000000, cen;
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++)
dis[i]=p[i];
dfs(0, 0);
for(int i=0; i<n; i++)
{
int cnt=0;
for(int c : g[i])
{
if(c==par[i])
cnt=max(cnt, dis[0]-dis[i]);
else cnt=max(cnt, dis[c]);
}
if(cnt<ans) ans=cnt, cen=i;
}
return cen;
}
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... |