이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define f first
#define s second
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vii vector<pair<int, int>>
#define vvb vector<vector<bool>>
#define piii pair<int, pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define inf 987654321
#define pb push_back
#define p push
#define ll long long
#define ull unsigned long long
#define g get
#define dbl double
#define mn 1000005
int N, P[mn];
vi adj[mn];
int fans;
int ans[mn];
int dfs (int loc, int par)
{
int sb = 0, mb = 0;
for (auto i : adj[loc])
if (i != par)
sb += dfs(i, loc), mb = max(mb, dfs(i, loc));
ans[loc] = max(mb, fans - sb - P[loc]);
return sb + P[loc];
}
int LocateCentre(int fN, int fP[mn], int S[mn], int D[mn])
{
N = fN;
for (int i = 0; i < N; i++)
P[i] = fP[i], fans += P[i];
for (int i = 0; i < N - 1; i++)
adj[S[i]].pb({D[i]}), adj[D[i]].pb({S[i]});
dfs(0, -1);
int bc = inf, bl;
for (int i = 0; i < N; i++)
if (bc > ans[i])
bc = ans[i], bl = i;
return bl;
}
/*int main(void)
{
cout << "TR" << endl;
int N, P[mn], S[mn], D[mn];
cin >> N;
for (int i = 0; i < N; i++)
cin >> P[i];
for (int i = 0; i < N - 1; i++)
cin >> S[i];
for (int i = 0; i < N - 1; i++)
cin >> D[i];
cout << LocateCentre(N, P, S, D);
}*/
컴파일 시 표준 에러 (stderr) 메시지
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:51:12: warning: 'bl' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | return bl;
| ^~
# | 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... |