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;
#define pb push_back
#define fi first
#define si second
typedef pair<int,int> pi;
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 69
#endif
template <typename Arg>
void __f(string name, Arg arg) {
cerr << name << " = " << arg << endl;
}
template <typename Head, typename... Tail>
void __f(string names, Head head, Tail... tail) {
string cur = "";
for (auto ch: names){if(ch==','){break;}else{cur+=ch;}}
string nxt = names.substr(cur.size()+2);
cerr << cur << " = " << head << ", ";
__f(nxt, tail...);
}
const int MXN = 1000005, INF = 2e9 + 10;
int sz[MXN], ans[MXN], best = INF, total, num[MXN], ret;
vector<int> adj[MXN];
void dfs(int x, int p) {
for (auto i: adj[x]) if (i != p) {
dfs(i, x);
num[x] += num[i];
ans[x] = max(ans[x], num[x]);
}
ans[x] = max(ans[x], total - num[x] - sz[x]);
num[x] += sz[x];
}
int LocateCentre(int N, int P[], int S[], int D[]) {
for (int i = 0; i < N; ++i) {
total += P[i];
sz[i] = 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);
for (int i = 0; i < N; ++i) {
if (ans[i] < best) {
ret = i;
best = ans[i];
}
debug(ans[i], i);
}
return ret;
}
Compilation message (stderr)
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:13:20: warning: statement has no effect [-Wunused-value]
13 | #define debug(...) 69
| ^~
traffic.cpp:57:3: note: in expansion of macro 'debug'
57 | debug(ans[i], i);
| ^~~~~
# | 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... |