Submission #1057432

# Submission time Handle Problem Language Result Execution time Memory
1057432 2024-08-13T19:35:36 Z n1k Beech Tree (IOI23_beechtree) C++17
80 / 100
2000 ms 254940 KB
#include "beechtree.h"
#include <bits/stdc++.h>

using namespace std;

std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){
    vector<multiset<pair<int, map<int, int>>>> c(N);
    vector<vector<int>> g(N);
    vector<int> ans(N, 1), sz(N, 1);
    for(int i=1; i<N; i++){
        g[P[i]].push_back(i);
    }
    auto check = [&](auto a, auto b){
        bool ok = a.size() >= b.size();
        for(auto [k, v]:b){
            ok &= a[k]>=v;
        }
        return ok;
    };
    auto add = [&](auto p, auto u){
        bool ok = 1;
        auto it = c[u].insert(p);
        if(next(it)!=c[u].end()){
            ok&=check(next(it)->second, it->second);
        }
        if(it!=c[u].begin()){
            ok&=check(it->second, prev(it)->second);
        } 
        return ok;
    };
    function<void(int)> dfs = [&](int u){
        map<int, int> cur;
        for(auto v:g[u]){
            dfs(v);
            sz[u]+=sz[v];
            ans[u]&=ans[v];
            ans[u]&= !cur.count(C[v]);
            cur[C[v]] = sz[v];

            if(c[u].size() < c[v].size()){
                swap(c[u], c[v]);
            }
            // insert
            for(auto p:c[v]){
                ans[u]&=add(p, u);
            }
        }
        ans[u]&=add(make_pair(sz[u], cur), u);
    };

    dfs(0);

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 440 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 440 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 148 ms 115440 KB Output is correct
8 Correct 145 ms 115540 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 140 ms 115380 KB Output is correct
18 Correct 140 ms 115540 KB Output is correct
19 Correct 140 ms 115588 KB Output is correct
20 Correct 147 ms 115516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 696 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 129 ms 50628 KB Output is correct
16 Correct 129 ms 47700 KB Output is correct
17 Correct 125 ms 48212 KB Output is correct
18 Correct 119 ms 49748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 148 ms 115440 KB Output is correct
6 Correct 145 ms 115540 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 3 ms 1116 KB Output is correct
11 Correct 266 ms 96880 KB Output is correct
12 Execution timed out 2058 ms 42196 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 432 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 432 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 440 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 440 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 440 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 440 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 2 ms 1368 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 1 ms 1472 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 3 ms 1628 KB Output is correct
32 Correct 3 ms 1628 KB Output is correct
33 Correct 2 ms 1424 KB Output is correct
34 Correct 3 ms 2084 KB Output is correct
35 Correct 3 ms 1884 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 1 ms 1116 KB Output is correct
38 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 432 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 432 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 440 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 440 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 1372 KB Output is correct
43 Correct 1 ms 1372 KB Output is correct
44 Correct 1 ms 1372 KB Output is correct
45 Correct 2 ms 1372 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 860 KB Output is correct
57 Correct 1 ms 696 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
59 Correct 2 ms 860 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 2 ms 1372 KB Output is correct
63 Correct 3 ms 1116 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 524 KB Output is correct
75 Correct 1 ms 1372 KB Output is correct
76 Correct 2 ms 1368 KB Output is correct
77 Correct 1 ms 1372 KB Output is correct
78 Correct 1 ms 1472 KB Output is correct
79 Correct 1 ms 1372 KB Output is correct
80 Correct 2 ms 1372 KB Output is correct
81 Correct 3 ms 1628 KB Output is correct
82 Correct 3 ms 1628 KB Output is correct
83 Correct 2 ms 1424 KB Output is correct
84 Correct 3 ms 2084 KB Output is correct
85 Correct 3 ms 1884 KB Output is correct
86 Correct 2 ms 1372 KB Output is correct
87 Correct 1 ms 1116 KB Output is correct
88 Correct 2 ms 1372 KB Output is correct
89 Correct 2 ms 1372 KB Output is correct
90 Correct 2 ms 1236 KB Output is correct
91 Correct 3 ms 1628 KB Output is correct
92 Correct 3 ms 1472 KB Output is correct
93 Correct 2 ms 1372 KB Output is correct
94 Correct 3 ms 1628 KB Output is correct
95 Correct 3 ms 1628 KB Output is correct
96 Correct 2 ms 1384 KB Output is correct
97 Correct 1 ms 1212 KB Output is correct
98 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 440 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 440 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 2 ms 1368 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 1 ms 1472 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 3 ms 1628 KB Output is correct
32 Correct 3 ms 1628 KB Output is correct
33 Correct 2 ms 1424 KB Output is correct
34 Correct 3 ms 2084 KB Output is correct
35 Correct 3 ms 1884 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 1 ms 1116 KB Output is correct
38 Correct 2 ms 1372 KB Output is correct
39 Correct 148 ms 114632 KB Output is correct
40 Correct 147 ms 114744 KB Output is correct
41 Correct 141 ms 114656 KB Output is correct
42 Correct 132 ms 114772 KB Output is correct
43 Correct 165 ms 103252 KB Output is correct
44 Correct 195 ms 99392 KB Output is correct
45 Correct 621 ms 216404 KB Output is correct
46 Correct 498 ms 193364 KB Output is correct
47 Correct 429 ms 166488 KB Output is correct
48 Correct 362 ms 131668 KB Output is correct
49 Correct 296 ms 101764 KB Output is correct
50 Correct 723 ms 254940 KB Output is correct
51 Correct 609 ms 231224 KB Output is correct
52 Correct 487 ms 186748 KB Output is correct
53 Correct 398 ms 140720 KB Output is correct
54 Correct 287 ms 101380 KB Output is correct
55 Correct 169 ms 90636 KB Output is correct
56 Correct 164 ms 90792 KB Output is correct
57 Correct 211 ms 97108 KB Output is correct
58 Correct 219 ms 97620 KB Output is correct
59 Correct 223 ms 97620 KB Output is correct
60 Correct 223 ms 97620 KB Output is correct
61 Correct 250 ms 97360 KB Output is correct
62 Correct 268 ms 96852 KB Output is correct
63 Correct 192 ms 90300 KB Output is correct
64 Correct 192 ms 99668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 432 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 432 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 440 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 440 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 148 ms 115440 KB Output is correct
39 Correct 145 ms 115540 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 1372 KB Output is correct
45 Correct 1 ms 1372 KB Output is correct
46 Correct 1 ms 1372 KB Output is correct
47 Correct 2 ms 1372 KB Output is correct
48 Correct 140 ms 115380 KB Output is correct
49 Correct 140 ms 115540 KB Output is correct
50 Correct 140 ms 115588 KB Output is correct
51 Correct 147 ms 115516 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 860 KB Output is correct
63 Correct 1 ms 696 KB Output is correct
64 Correct 1 ms 860 KB Output is correct
65 Correct 2 ms 860 KB Output is correct
66 Correct 129 ms 50628 KB Output is correct
67 Correct 129 ms 47700 KB Output is correct
68 Correct 125 ms 48212 KB Output is correct
69 Correct 119 ms 49748 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 2 ms 1372 KB Output is correct
73 Correct 3 ms 1116 KB Output is correct
74 Correct 266 ms 96880 KB Output is correct
75 Execution timed out 2058 ms 42196 KB Time limit exceeded
76 Halted 0 ms 0 KB -