#include <bits/stdc++.h>
#include "traffic.h"
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef pair<int,int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
const int mxn = 1e6;
vi adj[mxn];
int sz[mxn];
int mx[mxn];
void dfs(int u, int p){
for(auto v: adj[u]){
if(v == p)
continue;
dfs(v, u);
sz[u] += sz[v];
mx[u] = max(mx[u], sz[v]);
}
}
int LocateCentre(int n, int p[], int s[], int d[]){
for(int i = 0; i < n-1; i++){
adj[s[i]].push_back(d[i]);
adj[d[i]].push_back(s[i]);
}
int total = 0;
for(int i = 0; i < n; i++){
sz[i] = p[i];
total += p[i];
}
dfs(0, -1);
int wt = mxn + 10;
int res = -1;
for(int i = 0; i < n; i++){
int temp = max(mx[i], total - sz[i]);
if(temp < wt){
wt = temp;
res = i;
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Incorrect |
12 ms |
23820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Incorrect |
12 ms |
23820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Incorrect |
12 ms |
23820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Incorrect |
12 ms |
23820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |