# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
317022 | nandonathaniel | Traffic (IOI10_traffic) | C++14 | 15 ms | 23808 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=1e6+5;
vector<int> adj[MAXN];
int subtree[MAXN],atas[MAXN];
void dfs(int now,int par){
atas[now]=par;
for(auto nxt : adj[now]){
if(nxt==par)continue;
dfs(nxt,now);
subtree[now]+=subtree[nxt];
}
}
int LocateCentre(int N, int P[], int S[], int D[])
{
for(int i=0;i<N;i++)subtree[i]=P[i];
for(int i=0;i<N-1;i++){
adj[S[i]].push_back(D[i]);
adj[D[i]].push_back(S[i]);
}
dfs(0,-1);
int ans=1e9,idx;
for(int i=0;i<N;i++){
int ret=0;
for(auto j : adj[i]){
if(j==atas[i])ret=max(ret,N-subtree[i]);
else ret=max(ret,subtree[j]);
}
if(ret<ans){
ans=ret;
idx=i;
}
}
return idx;
}
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... |