# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
282347 | iliccmarko | Traffic (IOI10_traffic) | C++14 | 0 ms | 0 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;
#define ll long long
#define endl "\n"
using namespace std;
long long dfs(int u, int pret, vector<vector<int> > g, long long &ans, int &ind, long long svi, int p[])
{
long long br = 0;
for(int i = 0;i<(int)g[u].size();i++)
{
int s = g[u][i];
if(s==pret) continue;
br+=dfs(s, u, g, ans, ind, svi, p);
}
if(br<ans)
{
ans = br;
ind = u;
}
if(svi - br - p[u]<ans)
{
ans = svi - br - p[u];
ind = u;
}
return br + p[u];
}
int LocateCenter(int n, int p[], int s[], int d[])
{
vector<vector<int> > g(1000);
for(int i = 0;i<n-1;i++)
{
int a = s[i];
int b = d[i];
g[a].push_back(b);
g[b].push_back(a);
}
long long svi = 0;
for(int i = 0;i<n;i++)
{
svi+=p[i];
}
long long ans = LLONG_MAX;
int ind;
dfs(1, -1, g, ans, ind, svi, p);
return ind;
}