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 <algorithm>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
const int N = 1000003,INF=2000000001;
int n;
vector<pair<int,int> > a[N];
int b[N];
int sum, ans = INF, ansi;
int dfs(int x, int p)
{
int res=0;
int yans=0;
for (int i = 0; i < a[x].size(); ++i)
{
int h = a[x][i].first;
if (h == p)
continue;
a[x][i].second = dfs(h,x);
res += a[x][i].second;
yans = max(yans, a[x][i].second);
}
yans = max(yans, sum - res - b[x]);
if (yans < ans)
{
ans = yans;
ansi = x;
}
return res + b[x];
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
n = N;
for (int i = 0; i < n; ++i)
{
b[i] = pp[i];
sum += b[i];
}
for (int i = 0; i < n - 1; ++i)
{
a[S[i]].push_back(make_pair(D[i],0));
a[D[i]].push_back(make_pair(S[i],0));
}
dfs(0,-1);
return ansi;
}
Compilation message (stderr)
traffic.cpp: In function 'int dfs(int, int)':
traffic.cpp:17:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a[x].size(); ++i)
~~^~~~~~~~~~~~~
# | 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... |