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;
int dfs(int u, int pret, vector<vector<int> > g, int &ans, int &ind, int svi, int p[])
{
int 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);
}
int maks = max(br, svi - p[u] - br);
if(maks<ans)
{
ans = maks;
ind = u;
}
return br + p[u];
}
int LocateCentre(int n, int *p, int *s, int *d)
{
vector<vector<int> > g(n+5);
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);
}
int svi = 0;
for(int i = 0;i<n;i++)
{
svi+=p[i];
}
int ans = svi;
int ind;
dfs(0, -1, g, ans, ind, svi, p);
return ind;
}
# | 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... |