#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int n, m;
vector<int> p, c;
vector<int> adj[202020], res;
int sz[202020];
void solve(int v) {
sz[v] = 1;
for (int i = 0; i < adj[v].size(); i++) {
int u = adj[v][i];
solve(u);
sz[v] += sz[u];
}
priority_queue<pii> pq;
vector<int> vec;
pq.push({sz[v], v});
while (!pq.empty()) {
int now = pq.top().second;
vec.push_back(now);
pq.pop();
for (int i = 0; i < adj[now].size(); i++) {
int u = adj[now][i];
pq.push({sz[u], u});
}
}
map<int, int> cnt;
for (int i = 1; i < sz[v]; i++) {
int now = vec[i], par;
if (cnt.find(c[now]) == cnt.end()) {
par = vec[0];
cnt.insert({c[now], 1});
}
else par = vec[cnt[c[now]]];
if (par != p[now]) {
res[v] = 0;
return;
}
}
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C) {
n = N; m = M; p = P; c = C;
for (int i = 1; i < n; i++) {
adj[p[i]].push_back(i);
}
for (int i = 0; i < n; i++) res.push_back(1);
solve(0);
return res;
}
Compilation message
beechtree.cpp: In function 'void solve(int)':
beechtree.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for (int i = 0; i < adj[v].size(); i++) {
| ~~^~~~~~~~~~~~~~~
beechtree.cpp:27:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i = 0; i < adj[now].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Incorrect |
2 ms |
5724 KB |
2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Incorrect |
1 ms |
5724 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Incorrect |
1 ms |
5724 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5720 KB |
Output is correct |
4 |
Correct |
2 ms |
5720 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5720 KB |
Output is correct |
8 |
Correct |
2 ms |
5724 KB |
Output is correct |
9 |
Incorrect |
1 ms |
5724 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Execution timed out |
2065 ms |
67736 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Incorrect |
2 ms |
5724 KB |
2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5720 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5724 KB |
Output is correct |
11 |
Correct |
2 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5724 KB |
Output is correct |
16 |
Incorrect |
2 ms |
5724 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Incorrect |
2 ms |
5724 KB |
2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5720 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5724 KB |
Output is correct |
11 |
Correct |
2 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5724 KB |
Output is correct |
16 |
Incorrect |
2 ms |
5724 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Incorrect |
2 ms |
5724 KB |
2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |