Submission #1057530

# Submission time Handle Problem Language Result Execution time Memory
1057530 2024-08-13T21:01:52 Z n1k Beech Tree (IOI23_beechtree) C++17
80 / 100
2000 ms 258840 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), len(N);
    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){
        len[u]+=p.second.size();
        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(len[u] < len[v]){
                swap(c[u], c[v]);
                swap(len[u], len[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 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 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 344 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 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 344 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 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 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 344 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 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 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 160 ms 113748 KB Output is correct
8 Correct 150 ms 113744 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 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 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 1 ms 1424 KB Output is correct
17 Correct 137 ms 113752 KB Output is correct
18 Correct 150 ms 113744 KB Output is correct
19 Correct 153 ms 113744 KB Output is correct
20 Correct 152 ms 113884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 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 348 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 143 ms 50108 KB Output is correct
16 Correct 124 ms 47156 KB Output is correct
17 Correct 146 ms 47696 KB Output is correct
18 Correct 131 ms 49152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 160 ms 113748 KB Output is correct
6 Correct 150 ms 113744 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 97852 KB Output is correct
12 Execution timed out 2064 ms 23636 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 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 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 344 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 344 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 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 344 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 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 344 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 1 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 0 ms 344 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 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 1 ms 348 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 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 0 ms 348 KB Output is correct
13 Correct 0 ms 344 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 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 2 ms 1372 KB Output is correct
26 Correct 1 ms 1372 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 1 ms 1372 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 3 ms 1372 KB Output is correct
34 Correct 4 ms 1884 KB Output is correct
35 Correct 4 ms 1884 KB Output is correct
36 Correct 4 ms 1372 KB Output is correct
37 Correct 2 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 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 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 344 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 344 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 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 344 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 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 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 1 ms 1424 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 344 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 1 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 860 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
59 Correct 1 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 0 ms 344 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1 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 1 ms 348 KB Output is correct
74 Correct 1 ms 344 KB Output is correct
75 Correct 2 ms 1372 KB Output is correct
76 Correct 1 ms 1372 KB Output is correct
77 Correct 1 ms 1372 KB Output is correct
78 Correct 1 ms 1372 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 3 ms 1372 KB Output is correct
84 Correct 4 ms 1884 KB Output is correct
85 Correct 4 ms 1884 KB Output is correct
86 Correct 4 ms 1372 KB Output is correct
87 Correct 2 ms 1116 KB Output is correct
88 Correct 2 ms 1372 KB Output is correct
89 Correct 2 ms 1368 KB Output is correct
90 Correct 2 ms 1372 KB Output is correct
91 Correct 3 ms 1628 KB Output is correct
92 Correct 3 ms 1628 KB Output is correct
93 Correct 2 ms 1444 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 1372 KB Output is correct
97 Correct 1 ms 1116 KB Output is correct
98 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 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 0 ms 348 KB Output is correct
13 Correct 0 ms 344 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 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 2 ms 1372 KB Output is correct
26 Correct 1 ms 1372 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 1 ms 1372 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 3 ms 1372 KB Output is correct
34 Correct 4 ms 1884 KB Output is correct
35 Correct 4 ms 1884 KB Output is correct
36 Correct 4 ms 1372 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 2 ms 1372 KB Output is correct
39 Correct 139 ms 113780 KB Output is correct
40 Correct 143 ms 113796 KB Output is correct
41 Correct 137 ms 113812 KB Output is correct
42 Correct 142 ms 113932 KB Output is correct
43 Correct 175 ms 102224 KB Output is correct
44 Correct 198 ms 98392 KB Output is correct
45 Correct 625 ms 219732 KB Output is correct
46 Correct 529 ms 196692 KB Output is correct
47 Correct 427 ms 169808 KB Output is correct
48 Correct 353 ms 135252 KB Output is correct
49 Correct 313 ms 104784 KB Output is correct
50 Correct 740 ms 258840 KB Output is correct
51 Correct 611 ms 235092 KB Output is correct
52 Correct 497 ms 190548 KB Output is correct
53 Correct 401 ms 144392 KB Output is correct
54 Correct 296 ms 104712 KB Output is correct
55 Correct 180 ms 96432 KB Output is correct
56 Correct 174 ms 96852 KB Output is correct
57 Correct 213 ms 103160 KB Output is correct
58 Correct 225 ms 103504 KB Output is correct
59 Correct 238 ms 103504 KB Output is correct
60 Correct 236 ms 103248 KB Output is correct
61 Correct 237 ms 102912 KB Output is correct
62 Correct 239 ms 102484 KB Output is correct
63 Correct 200 ms 89680 KB Output is correct
64 Correct 197 ms 98644 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 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 344 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 344 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 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 344 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 160 ms 113748 KB Output is correct
39 Correct 150 ms 113744 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 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 1 ms 1424 KB Output is correct
48 Correct 137 ms 113752 KB Output is correct
49 Correct 150 ms 113744 KB Output is correct
50 Correct 153 ms 113744 KB Output is correct
51 Correct 152 ms 113884 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 344 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 1 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 860 KB Output is correct
64 Correct 1 ms 860 KB Output is correct
65 Correct 1 ms 860 KB Output is correct
66 Correct 143 ms 50108 KB Output is correct
67 Correct 124 ms 47156 KB Output is correct
68 Correct 146 ms 47696 KB Output is correct
69 Correct 131 ms 49152 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 97852 KB Output is correct
75 Execution timed out 2064 ms 23636 KB Time limit exceeded
76 Halted 0 ms 0 KB -