#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;
#define MAXN 1000005
vector<int> edges[MAXN];
long long best = INT_MAX;
long long totSum = 0;
long long subtree[MAXN];
long long vals[MAXN];
void dfs(int src, int par) {
long long val = 0;
long long 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);
best = min(best, val);
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 best;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Incorrect |
17 ms |
23808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Incorrect |
17 ms |
23808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Incorrect |
17 ms |
23808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Incorrect |
17 ms |
23808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |