#include "beechtree.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using ld = long double;
//#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
const int nmax = 3e5 + 5;
vector<pii> g[nmax];
vector<int> P, C;
unordered_set<int> colors[nmax], play[nmax];
bool isanc(unordered_set<int>& A, unordered_set<int>& B) {
if(sz(A) < sz(B)) return 0;
for(auto &x : B)
if(!A.count(x)) return 0;
return 1;
}
vector<int> sol;
int h[nmax];
bool superimposable(int x, int y) { // x peste y
//if(sz(g[x]) == 0 || x == y) return 1;
//if(calc[x][y]) return SI[x][y];
map<int, int> gy;
for(auto [a, c] : g[y]) gy[c] = a;
//calc[x][y] = 1;
//SI[x][y] = 1;
for(auto [a, c] : g[x]) {
if(gy.count(c) == 0) { return 0; }
if(!superimposable(a, gy[c])) { return 0; }
}
return 1;
}
int area[nmax];
vector<int> dfs(int node) {
vector<int> here;
sol[node] = 1;
area[node] = 1;
here.emplace_back(node);
for(auto [x, c] : g[node]) {
auto T = dfs(x);
area[node] += area[x];
sol[node] &= sol[x];
copy(all(T), back_inserter(here));
}
if(sz(g[node]) != sz(colors[node])) sol[node] = 0;
if(sol[node] == 0) { return here; }
sort(all(here), [&](int a, int b) { return area[a] < area[b]; });
for(int i = 0; sol[node] && i < sz(here) - 1; i++)
if(!superimposable(here[i], here[i + 1])) { sol[node] = 0; }
return here;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P_, std::vector<int> C_) {
P = P_;
C = C_;
for(int i = 1; i < N; i++) {
g[P[i]].emplace_back(i, C[i]);
colors[P[i]].emplace(C[i]);
}
sol.assign(N, 0);
dfs(0);
return sol;
}
/**
Töte es durch genaue Untersuchung\Töte es kann es nur noch schlimmer machen\Es lässt es irgendwie atmen
--
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
40284 KB |
Output is correct |
2 |
Correct |
8 ms |
40284 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
40280 KB |
Output is correct |
2 |
Correct |
8 ms |
40280 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
4 |
Correct |
8 ms |
40376 KB |
Output is correct |
5 |
Correct |
8 ms |
40280 KB |
Output is correct |
6 |
Correct |
8 ms |
40440 KB |
Output is correct |
7 |
Correct |
8 ms |
40284 KB |
Output is correct |
8 |
Correct |
8 ms |
40484 KB |
Output is correct |
9 |
Correct |
9 ms |
40452 KB |
Output is correct |
10 |
Correct |
8 ms |
40280 KB |
Output is correct |
11 |
Correct |
8 ms |
40280 KB |
Output is correct |
12 |
Correct |
8 ms |
40284 KB |
Output is correct |
13 |
Correct |
8 ms |
40432 KB |
Output is correct |
14 |
Correct |
8 ms |
40284 KB |
Output is correct |
15 |
Correct |
8 ms |
40432 KB |
Output is correct |
16 |
Correct |
9 ms |
40280 KB |
Output is correct |
17 |
Correct |
8 ms |
40284 KB |
Output is correct |
18 |
Correct |
9 ms |
40280 KB |
Output is correct |
19 |
Correct |
8 ms |
40284 KB |
Output is correct |
20 |
Correct |
8 ms |
40284 KB |
Output is correct |
21 |
Correct |
8 ms |
40284 KB |
Output is correct |
22 |
Correct |
9 ms |
40476 KB |
Output is correct |
23 |
Correct |
8 ms |
40284 KB |
Output is correct |
24 |
Correct |
8 ms |
40284 KB |
Output is correct |
25 |
Correct |
8 ms |
40284 KB |
Output is correct |
26 |
Correct |
9 ms |
40456 KB |
Output is correct |
27 |
Correct |
8 ms |
40280 KB |
Output is correct |
28 |
Correct |
8 ms |
40280 KB |
Output is correct |
29 |
Correct |
8 ms |
40284 KB |
Output is correct |
30 |
Correct |
8 ms |
40284 KB |
Output is correct |
31 |
Correct |
9 ms |
40284 KB |
Output is correct |
32 |
Correct |
10 ms |
40436 KB |
Output is correct |
33 |
Correct |
8 ms |
40280 KB |
Output is correct |
34 |
Correct |
8 ms |
40284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
40280 KB |
Output is correct |
2 |
Correct |
8 ms |
40280 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
4 |
Correct |
8 ms |
40376 KB |
Output is correct |
5 |
Correct |
8 ms |
40280 KB |
Output is correct |
6 |
Correct |
8 ms |
40440 KB |
Output is correct |
7 |
Execution timed out |
2061 ms |
110780 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
40280 KB |
Output is correct |
2 |
Correct |
8 ms |
40284 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
4 |
Correct |
8 ms |
40284 KB |
Output is correct |
5 |
Correct |
7 ms |
40284 KB |
Output is correct |
6 |
Correct |
8 ms |
40284 KB |
Output is correct |
7 |
Correct |
9 ms |
40448 KB |
Output is correct |
8 |
Correct |
8 ms |
40280 KB |
Output is correct |
9 |
Correct |
9 ms |
40284 KB |
Output is correct |
10 |
Correct |
8 ms |
40284 KB |
Output is correct |
11 |
Correct |
9 ms |
40536 KB |
Output is correct |
12 |
Correct |
9 ms |
40440 KB |
Output is correct |
13 |
Correct |
8 ms |
40440 KB |
Output is correct |
14 |
Correct |
9 ms |
40540 KB |
Output is correct |
15 |
Correct |
68 ms |
51684 KB |
Output is correct |
16 |
Correct |
84 ms |
52188 KB |
Output is correct |
17 |
Correct |
80 ms |
52180 KB |
Output is correct |
18 |
Correct |
81 ms |
52488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
40280 KB |
Output is correct |
2 |
Correct |
8 ms |
40280 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
4 |
Correct |
8 ms |
40484 KB |
Output is correct |
5 |
Execution timed out |
2061 ms |
110780 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
40284 KB |
Output is correct |
2 |
Correct |
8 ms |
40284 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
4 |
Correct |
8 ms |
40280 KB |
Output is correct |
5 |
Correct |
8 ms |
40280 KB |
Output is correct |
6 |
Correct |
8 ms |
40284 KB |
Output is correct |
7 |
Correct |
8 ms |
40376 KB |
Output is correct |
8 |
Correct |
8 ms |
40280 KB |
Output is correct |
9 |
Correct |
8 ms |
40440 KB |
Output is correct |
10 |
Correct |
8 ms |
40284 KB |
Output is correct |
11 |
Correct |
8 ms |
40484 KB |
Output is correct |
12 |
Correct |
9 ms |
40452 KB |
Output is correct |
13 |
Correct |
8 ms |
40280 KB |
Output is correct |
14 |
Correct |
8 ms |
40280 KB |
Output is correct |
15 |
Correct |
8 ms |
40284 KB |
Output is correct |
16 |
Correct |
8 ms |
40432 KB |
Output is correct |
17 |
Correct |
8 ms |
40284 KB |
Output is correct |
18 |
Correct |
8 ms |
40432 KB |
Output is correct |
19 |
Correct |
9 ms |
40280 KB |
Output is correct |
20 |
Correct |
8 ms |
40284 KB |
Output is correct |
21 |
Correct |
9 ms |
40280 KB |
Output is correct |
22 |
Correct |
8 ms |
40284 KB |
Output is correct |
23 |
Correct |
8 ms |
40284 KB |
Output is correct |
24 |
Correct |
8 ms |
40284 KB |
Output is correct |
25 |
Correct |
9 ms |
40476 KB |
Output is correct |
26 |
Correct |
8 ms |
40284 KB |
Output is correct |
27 |
Correct |
8 ms |
40284 KB |
Output is correct |
28 |
Correct |
8 ms |
40284 KB |
Output is correct |
29 |
Correct |
9 ms |
40456 KB |
Output is correct |
30 |
Correct |
8 ms |
40280 KB |
Output is correct |
31 |
Correct |
8 ms |
40280 KB |
Output is correct |
32 |
Correct |
8 ms |
40284 KB |
Output is correct |
33 |
Correct |
8 ms |
40284 KB |
Output is correct |
34 |
Correct |
9 ms |
40284 KB |
Output is correct |
35 |
Correct |
10 ms |
40436 KB |
Output is correct |
36 |
Correct |
8 ms |
40280 KB |
Output is correct |
37 |
Correct |
8 ms |
40284 KB |
Output is correct |
38 |
Correct |
9 ms |
40280 KB |
Output is correct |
39 |
Correct |
8 ms |
40284 KB |
Output is correct |
40 |
Correct |
8 ms |
40284 KB |
Output is correct |
41 |
Correct |
8 ms |
40284 KB |
Output is correct |
42 |
Correct |
7 ms |
40284 KB |
Output is correct |
43 |
Correct |
8 ms |
40284 KB |
Output is correct |
44 |
Correct |
9 ms |
40448 KB |
Output is correct |
45 |
Correct |
8 ms |
40280 KB |
Output is correct |
46 |
Correct |
9 ms |
40284 KB |
Output is correct |
47 |
Correct |
8 ms |
40284 KB |
Output is correct |
48 |
Correct |
54 ms |
40540 KB |
Output is correct |
49 |
Correct |
9 ms |
40540 KB |
Output is correct |
50 |
Correct |
9 ms |
40540 KB |
Output is correct |
51 |
Correct |
8 ms |
40536 KB |
Output is correct |
52 |
Correct |
8 ms |
40284 KB |
Output is correct |
53 |
Correct |
10 ms |
40368 KB |
Output is correct |
54 |
Correct |
8 ms |
40536 KB |
Output is correct |
55 |
Correct |
8 ms |
40448 KB |
Output is correct |
56 |
Correct |
7 ms |
40280 KB |
Output is correct |
57 |
Correct |
8 ms |
40284 KB |
Output is correct |
58 |
Correct |
9 ms |
40472 KB |
Output is correct |
59 |
Correct |
9 ms |
40280 KB |
Output is correct |
60 |
Correct |
8 ms |
40284 KB |
Output is correct |
61 |
Correct |
8 ms |
40280 KB |
Output is correct |
62 |
Correct |
9 ms |
40284 KB |
Output is correct |
63 |
Correct |
10 ms |
40284 KB |
Output is correct |
64 |
Correct |
12 ms |
40284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
40280 KB |
Output is correct |
2 |
Correct |
8 ms |
40280 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
4 |
Correct |
8 ms |
40484 KB |
Output is correct |
5 |
Correct |
9 ms |
40452 KB |
Output is correct |
6 |
Correct |
8 ms |
40280 KB |
Output is correct |
7 |
Correct |
8 ms |
40280 KB |
Output is correct |
8 |
Correct |
8 ms |
40284 KB |
Output is correct |
9 |
Correct |
8 ms |
40432 KB |
Output is correct |
10 |
Correct |
8 ms |
40284 KB |
Output is correct |
11 |
Correct |
8 ms |
40432 KB |
Output is correct |
12 |
Correct |
9 ms |
40280 KB |
Output is correct |
13 |
Correct |
8 ms |
40284 KB |
Output is correct |
14 |
Correct |
9 ms |
40280 KB |
Output is correct |
15 |
Correct |
8 ms |
40284 KB |
Output is correct |
16 |
Correct |
8 ms |
40284 KB |
Output is correct |
17 |
Correct |
8 ms |
40284 KB |
Output is correct |
18 |
Correct |
9 ms |
40476 KB |
Output is correct |
19 |
Correct |
8 ms |
40284 KB |
Output is correct |
20 |
Correct |
8 ms |
40284 KB |
Output is correct |
21 |
Correct |
8 ms |
40284 KB |
Output is correct |
22 |
Correct |
9 ms |
40456 KB |
Output is correct |
23 |
Correct |
8 ms |
40280 KB |
Output is correct |
24 |
Correct |
8 ms |
40280 KB |
Output is correct |
25 |
Execution timed out |
2041 ms |
41168 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
40284 KB |
Output is correct |
2 |
Correct |
8 ms |
40284 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
4 |
Correct |
8 ms |
40280 KB |
Output is correct |
5 |
Correct |
8 ms |
40280 KB |
Output is correct |
6 |
Correct |
8 ms |
40284 KB |
Output is correct |
7 |
Correct |
8 ms |
40376 KB |
Output is correct |
8 |
Correct |
8 ms |
40280 KB |
Output is correct |
9 |
Correct |
8 ms |
40440 KB |
Output is correct |
10 |
Correct |
8 ms |
40284 KB |
Output is correct |
11 |
Correct |
8 ms |
40484 KB |
Output is correct |
12 |
Correct |
9 ms |
40452 KB |
Output is correct |
13 |
Correct |
8 ms |
40280 KB |
Output is correct |
14 |
Correct |
8 ms |
40280 KB |
Output is correct |
15 |
Correct |
8 ms |
40284 KB |
Output is correct |
16 |
Correct |
8 ms |
40432 KB |
Output is correct |
17 |
Correct |
8 ms |
40284 KB |
Output is correct |
18 |
Correct |
8 ms |
40432 KB |
Output is correct |
19 |
Correct |
9 ms |
40280 KB |
Output is correct |
20 |
Correct |
8 ms |
40284 KB |
Output is correct |
21 |
Correct |
9 ms |
40280 KB |
Output is correct |
22 |
Correct |
8 ms |
40284 KB |
Output is correct |
23 |
Correct |
8 ms |
40284 KB |
Output is correct |
24 |
Correct |
8 ms |
40284 KB |
Output is correct |
25 |
Correct |
9 ms |
40476 KB |
Output is correct |
26 |
Correct |
8 ms |
40284 KB |
Output is correct |
27 |
Correct |
8 ms |
40284 KB |
Output is correct |
28 |
Correct |
8 ms |
40284 KB |
Output is correct |
29 |
Correct |
9 ms |
40456 KB |
Output is correct |
30 |
Correct |
8 ms |
40280 KB |
Output is correct |
31 |
Correct |
8 ms |
40280 KB |
Output is correct |
32 |
Correct |
8 ms |
40284 KB |
Output is correct |
33 |
Correct |
8 ms |
40284 KB |
Output is correct |
34 |
Correct |
9 ms |
40284 KB |
Output is correct |
35 |
Correct |
10 ms |
40436 KB |
Output is correct |
36 |
Correct |
8 ms |
40280 KB |
Output is correct |
37 |
Correct |
8 ms |
40284 KB |
Output is correct |
38 |
Correct |
54 ms |
40540 KB |
Output is correct |
39 |
Correct |
9 ms |
40540 KB |
Output is correct |
40 |
Correct |
9 ms |
40540 KB |
Output is correct |
41 |
Correct |
8 ms |
40536 KB |
Output is correct |
42 |
Correct |
9 ms |
40280 KB |
Output is correct |
43 |
Correct |
8 ms |
40284 KB |
Output is correct |
44 |
Correct |
8 ms |
40284 KB |
Output is correct |
45 |
Correct |
8 ms |
40284 KB |
Output is correct |
46 |
Correct |
7 ms |
40284 KB |
Output is correct |
47 |
Correct |
8 ms |
40284 KB |
Output is correct |
48 |
Correct |
9 ms |
40448 KB |
Output is correct |
49 |
Correct |
8 ms |
40280 KB |
Output is correct |
50 |
Correct |
9 ms |
40284 KB |
Output is correct |
51 |
Correct |
8 ms |
40284 KB |
Output is correct |
52 |
Correct |
9 ms |
40536 KB |
Output is correct |
53 |
Correct |
9 ms |
40440 KB |
Output is correct |
54 |
Correct |
8 ms |
40440 KB |
Output is correct |
55 |
Correct |
9 ms |
40540 KB |
Output is correct |
56 |
Correct |
8 ms |
40284 KB |
Output is correct |
57 |
Correct |
10 ms |
40368 KB |
Output is correct |
58 |
Correct |
8 ms |
40536 KB |
Output is correct |
59 |
Correct |
8 ms |
40448 KB |
Output is correct |
60 |
Correct |
7 ms |
40280 KB |
Output is correct |
61 |
Correct |
8 ms |
40284 KB |
Output is correct |
62 |
Correct |
9 ms |
40472 KB |
Output is correct |
63 |
Correct |
9 ms |
40280 KB |
Output is correct |
64 |
Correct |
8 ms |
40284 KB |
Output is correct |
65 |
Correct |
8 ms |
40280 KB |
Output is correct |
66 |
Correct |
9 ms |
40284 KB |
Output is correct |
67 |
Correct |
10 ms |
40284 KB |
Output is correct |
68 |
Correct |
12 ms |
40284 KB |
Output is correct |
69 |
Execution timed out |
2041 ms |
41168 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
40280 KB |
Output is correct |
2 |
Correct |
8 ms |
40280 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
4 |
Correct |
8 ms |
40484 KB |
Output is correct |
5 |
Correct |
9 ms |
40452 KB |
Output is correct |
6 |
Correct |
8 ms |
40280 KB |
Output is correct |
7 |
Correct |
8 ms |
40280 KB |
Output is correct |
8 |
Correct |
8 ms |
40284 KB |
Output is correct |
9 |
Correct |
8 ms |
40432 KB |
Output is correct |
10 |
Correct |
8 ms |
40284 KB |
Output is correct |
11 |
Correct |
8 ms |
40432 KB |
Output is correct |
12 |
Correct |
9 ms |
40280 KB |
Output is correct |
13 |
Correct |
8 ms |
40284 KB |
Output is correct |
14 |
Correct |
9 ms |
40280 KB |
Output is correct |
15 |
Correct |
8 ms |
40284 KB |
Output is correct |
16 |
Correct |
8 ms |
40284 KB |
Output is correct |
17 |
Correct |
8 ms |
40284 KB |
Output is correct |
18 |
Correct |
9 ms |
40476 KB |
Output is correct |
19 |
Correct |
8 ms |
40284 KB |
Output is correct |
20 |
Correct |
8 ms |
40284 KB |
Output is correct |
21 |
Correct |
8 ms |
40284 KB |
Output is correct |
22 |
Correct |
9 ms |
40456 KB |
Output is correct |
23 |
Correct |
8 ms |
40280 KB |
Output is correct |
24 |
Correct |
8 ms |
40280 KB |
Output is correct |
25 |
Execution timed out |
2041 ms |
41168 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
40284 KB |
Output is correct |
2 |
Correct |
8 ms |
40284 KB |
Output is correct |
3 |
Correct |
8 ms |
40284 KB |
Output is correct |
4 |
Correct |
8 ms |
40280 KB |
Output is correct |
5 |
Correct |
8 ms |
40280 KB |
Output is correct |
6 |
Correct |
8 ms |
40284 KB |
Output is correct |
7 |
Correct |
8 ms |
40376 KB |
Output is correct |
8 |
Correct |
8 ms |
40280 KB |
Output is correct |
9 |
Correct |
8 ms |
40440 KB |
Output is correct |
10 |
Correct |
8 ms |
40284 KB |
Output is correct |
11 |
Correct |
8 ms |
40484 KB |
Output is correct |
12 |
Correct |
9 ms |
40452 KB |
Output is correct |
13 |
Correct |
8 ms |
40280 KB |
Output is correct |
14 |
Correct |
8 ms |
40280 KB |
Output is correct |
15 |
Correct |
8 ms |
40284 KB |
Output is correct |
16 |
Correct |
8 ms |
40432 KB |
Output is correct |
17 |
Correct |
8 ms |
40284 KB |
Output is correct |
18 |
Correct |
8 ms |
40432 KB |
Output is correct |
19 |
Correct |
9 ms |
40280 KB |
Output is correct |
20 |
Correct |
8 ms |
40284 KB |
Output is correct |
21 |
Correct |
9 ms |
40280 KB |
Output is correct |
22 |
Correct |
8 ms |
40284 KB |
Output is correct |
23 |
Correct |
8 ms |
40284 KB |
Output is correct |
24 |
Correct |
8 ms |
40284 KB |
Output is correct |
25 |
Correct |
9 ms |
40476 KB |
Output is correct |
26 |
Correct |
8 ms |
40284 KB |
Output is correct |
27 |
Correct |
8 ms |
40284 KB |
Output is correct |
28 |
Correct |
8 ms |
40284 KB |
Output is correct |
29 |
Correct |
9 ms |
40456 KB |
Output is correct |
30 |
Correct |
8 ms |
40280 KB |
Output is correct |
31 |
Correct |
8 ms |
40280 KB |
Output is correct |
32 |
Correct |
8 ms |
40284 KB |
Output is correct |
33 |
Correct |
8 ms |
40284 KB |
Output is correct |
34 |
Correct |
9 ms |
40284 KB |
Output is correct |
35 |
Correct |
10 ms |
40436 KB |
Output is correct |
36 |
Correct |
8 ms |
40280 KB |
Output is correct |
37 |
Correct |
8 ms |
40284 KB |
Output is correct |
38 |
Execution timed out |
2061 ms |
110780 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |