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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include "traffic.h"
using namespace std;
const int MAXN = 1e6+5;
vector<int> edges[MAXN];
int best = INT_MAX;
int ans = 0;
int totSum = 0;
int subtree[MAXN];
int vals[MAXN];
void dfs(int src, int par) {
int val = 0;
int curSum = vals[src];
for (auto i : edges[src]) {
if (i == par) {
continue;
}
dfs(i, src);
val = max(val, subtree[i]);
curSum += subtree[i];
}
val = max(val, totSum - curSum);
if (val < best) {
best = val;
ans = src;
}
subtree[src] = curSum;
}
int LocateCentre(int n, int p[MAXN], int s[MAXN], int d[MAXN]) {
for (int i = 0; i < n; i++) {
totSum += p[i];
vals[i] = p[i];
subtree[i] = 0;
if (i != n - 1) {
edges[s[i]].push_back(d[i]);
edges[d[i]].push_back(s[i]);
}
}
dfs(0, 0);
return ans;
}
# | 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... |