이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <traffic.h>
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
ll linf = 1e15+1;
inline void scoobydoobydoo(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
const int MAXN = 1e6+7;
ll vals[MAXN];
ll subSz[MAXN];
vector<ll> adj[MAXN];
vector<ll> children[MAXN];
ll buildTree(ll node, ll parent){
subSz[node] = vals[node];
for (ll x : adj[node]){
if (x != parent){
children[node].push_back(x);
subSz[node] += buildTree(x, node);
}
}
return subSz[node];
}
ll centroidFind(ll node, ll target){
for (auto& e : children[node]){
if (target < subSz[e])return centroidFind(e, target);
}
return node;
}
int LocateCentre(int N, int P[], int S[], int D[]){
for (int i = 0; i < N; i++)vals[i] = P[i];
for (int i = 0; i < N-1; i++){
adj[S[i]].push_back(D[i]);
adj[D[i]].push_back(S[i]);
}
return centroidFind(1, buildTree(1, 1)/2);
}
# | 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... |