# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
841670 | Batrr | Beech Tree (IOI23_beechtree) | C++17 | 2054 ms | 63404 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 "beechtree.h"
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 300500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;
vector<pii> g[N];
int n, m;
int ans[N];
int P[N], C[N];
int tin[N], timer;
vector<int> t[N];
int sz[N];
bool f(int v, int u) {
for (int i = 0, j = 0; i < g[u].size(); i++) {
while (j < g[v].size() && g[v][j].f != g[u][i].f)
j++;
if (j == g[v].size())
return false;
if (!f(g[v][j].s, g[u][i].s))
return false;
}
return true;
}
void dfs(int v) {
tin[v] = timer++;
sz[v] = 1;
ans[v] = 1;
vector<int> a;
for(int i = 0; i + 1 < g[v].size(); i++)
ans[v] &= (g[v][i].f != g[v][i + 1].f);
for (auto it: g[v]) {
int to = it.s;
a.pb(to);
dfs(to);
sz[v] += sz[to];
ans[v] &= ans[to];
ans[v] &= f(v, to);
}
sort(a.begin(), a.end(), [](int i, int j) {
return sz[i] > sz[j];
});
for (int i = 0; i + 1 < a.size(); i++)
ans[v] &= f(a[i], a[i + 1]);
}
vector<int> beechtree(int N, int M, vector<int> PP, vector<int> CC) {
n = N;
for (int i = 0; i < n; i++) {
g[i].clear();
P[i] = PP[i];
C[i] = CC[i];
ans[i] = 0;
}
for (int i = 1; i < n; i++)
g[P[i]].pb({C[i], i});
for (int i = 0; i < n; i++)
sort(g[i].begin(), g[i].end());
dfs(0);
return vector<int>(ans, ans + n);
}
Compilation message (stderr)
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |