#include <bits/stdc++.h>
#include "traffic.h"
using namespace std;
int LocateCentre(int N, int P[], int S[], int D[]){
vector<vector<long long>> tree(N);
vector<long long> maxim(N), total(N), vis(N), siz(N);
priority_queue<long long> que;
for(long long i = 0; i < N-1; i ++){
tree[S[i]].push_back(D[i]);
tree[D[i]].push_back(S[i]);
}
for(long long i = 0; i < N; i ++){
siz[i] = tree[i].size();
if(tree[i].size() == 1){
que.push(-(P[i] * 10000000 + i));
vis[i] = true;
}
}
while(!que.empty()){
long long val = (-que.top())/10000000, a = (-que.top())%10000000;
que.pop();
if(siz[a] == 0){
return a;
}
for(long long i : tree[a]){
siz[i]--;
if(vis[i])continue;
maxim[i] = max((long long)val, maxim[i]);
total[i] += val;
if(siz[i] == 1){
vis[i] = true;
que.push(-((total[i]+P[i]) *10000000+ i));
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |