# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879790 | TAhmed33 | Papričice (COCI20_papricice) | C++98 | 1053 ms | 34640 KiB |
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;
#pragma GCC optimize ("Ofast")
const int MAXN = 2e5 + 25;
const int bad = -1e7;
inline int comb (int a, int b, int c) {
return abs(2 * a - c) < abs(2 * b - c) ? a : b;
}
vector <int> adj[MAXN];
int sze[MAXN], n, in[MAXN], out[MAXN], t;
set <int> dd[MAXN];
int mn = 1e9;
void dfs (int pos, int par) {
sze[pos] = 1;
in[pos] = ++t;
int mx = bad;
for (auto j : adj[pos]) {
if (j == par) continue;
dfs(j, pos);
sze[pos] += sze[j];
if (dd[pos].size() < dd[j].size()) dd[pos].swap(dd[j]);
for (auto i : dd[j]) dd[pos].insert(i);
dd[j].clear();
}
for (auto i : dd[pos]) mx = comb(i, mx, sze[pos]);
dd[pos].insert(sze[pos]);
if (sze[pos] != 1 && pos != 1) mn = min(mn, max({n - sze[pos], sze[pos] - mx, mx}) - min({n - sze[pos], sze[pos] - mx, mx}));
out[pos] = t;
}
set <int> x;
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |