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>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
const int NMAX = (int)1e6 + 1;
vector<int>ad[NMAX];
int sum[NMAX],A[NMAX],ans = (int)1e9;
void dfs(int node,int parent) {
for (auto& x : ad[node])
if (x != parent) {
dfs(x,node);
sum[node] += sum[x];
}
}
void dfs1(int node,int parent,int sus) {
int cost = sus;
for (auto& x : ad[node])
if (x != parent)
cost += sum[x];
ans = min(ans,cost);
cout << node << ' ' << parent << ' ' << sus << ' ' << cost << '\n';
for (auto& x : ad[node])
if (x != parent)
dfs1(x,node,cost - sum[x] + A[x]);
}
int LocateCentre(int N,int P[],int S[],int D[]) {
for (int i = 0; i < N;++i)
sum[i] = A[i] = P[i];
for (int i = 0; i < N - 1;++i) {
ad[S[i]].push_back(D[i]);
ad[D[i]].push_back(S[i]);
}
dfs(0,0);
dfs1(0,0,0);
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... |