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 <bits/stdc++.h>
#include "traffic.h"
using namespace std;
int LocateCentre(int N, int P[], int S[], int D[]){
vector<set<int>> tree(N);
vector<int> maxim(N), total(N);
priority_queue<pair<int, int>> que;
for(int i = 0; i < N-1; i ++){
tree[S[i]].insert(D[i]);
tree[D[i]].insert(S[i]);
}
for(int i = 0; i < N; i ++){
if(tree[i].size() == 1){
que.push({-P[i], i});
}
}
while(!que.empty()){
int val = -que.top().first, a = que.top().second;
//cout << a << endl;
que.pop();
for(int i : tree[a]){
tree[i].erase(a);
maxim[i] = max(val, maxim[i]);
total[i] += val;
if(tree[i].size() == 1){
que.push({-(total[i]+P[a]), i});
}
if(tree[i].size() == 0){
return i;
}
}
}
return 0;
}
# | 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... |