제출 #796897

#제출 시각아이디문제언어결과실행 시간메모리
796897LiudasTraffic (IOI10_traffic)C++17
100 / 100
1253 ms94852 KiB
#include <bits/stdc++.h> using namespace std; int LocateCentre(int N, int P[], int S[], int D[]){ vector<vector<int>> tree(N); vector<int> maxim(N), total(N), vis(N), siz(N); vector<long long> PP(N); for(int i = 0; i < N; i ++){ PP[i] = P[i]; } priority_queue<long long> que; for(int i = 0; i < N-1; i ++){ tree[S[i]].push_back(D[i]); tree[D[i]].push_back(S[i]); } for(int i = 0; i < N; i ++){ siz[i] = tree[i].size(); if(tree[i].size() == 1){ que.push(-(PP[i] * 10000000+ i)); vis[i] = true; } } while(!que.empty()){ int val = -que.top()/ 10000000, a = (-que.top()) % 10000000; que.pop(); if(siz[a] == 0){ return (int)a; } for(int i : tree[a]){ siz[i]--; if(vis[i])continue; maxim[i] = max(val, maxim[i]); total[i] += val; if(siz[i] == 1){ vis[i] = true; que.push(-((total[i]+PP[i])* 10000000+i)); } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...