이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vii vector<pair<int, int>>
#define vi vector<int>
#define vl vector<long long>
#define vll vector<pair<long long, long long>>
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i = a;i<=b;i++)
#define f first
#define s second
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
#define start int tt;cin>>tt;rep(testcase, 1, tt)
#define print(k) cout<<"Case #"<<testcase<<": "<<k<<"\n";
#define endl "\n"
#define DEBUG(k) cerr<<k<<"\n";
vi adj[1000010];
int n, ans, a[1000010];
ll res = 1e18, sum = 0;
ll solve(int x, int pa) {
ll mv = 0, s = 0;
for (int i = 0; i < (int) adj[x].size(); i++) {
if (adj[x][i] == pa) continue;
ll t = solve(adj[x][i], x);
s += t;
mv = max(mv, t);
}
s += a[x];
mv = max(mv, sum - s);
if (res > mv) {
res = mv; ans = x;
}
return s;
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
n = N;
for (int i = 0; i < n; i++) {
a[i] = pp[i];
sum += a[i];
}
for (int i = 0; i < n - 1; i++) {
adj[S[i]].push_back(D[i]);
adj[D[i]].push_back(S[i]);
}
solve(0, -1);
return ans;
}
# | 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... |