답안 #1030044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030044 2024-07-21T17:27:00 Z Mr_Husanboy 참나무 (IOI23_beechtree) C++17
66 / 100
2000 ms 989692 KB
#include "beechtree.h"
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second

using namespace std;
typedef pair<int, int> pii;

const int N = 2e5 + 1;

struct Graph
{
    int cnt[N];
    bool con[N];
    set<pii> srt[N];
    map<int, vector<int>> col[N];
} graph;

bool check(int v, int u)
{
    for (auto &pr : graph.col[v])
    {
        auto &[col, vec] = pr;
        auto it = graph.col[u].find(col);
        if (it == graph.col[u].end())
        {
            return false;
        }
        if (graph.cnt[vec[0]] > graph.cnt[it->yy[0]])
        {
            return false;
        }
    }
    return true;
}

bool insertAndCheck(set<pii> &srt, pii p)
{
    auto [it, st] = srt.insert(p);
    bool result = true;
    if (it != srt.begin())
    {
        result &= check(prev(it)->yy, it->yy);
    }
    if (next(it) != srt.end())
    {
        result &= check(it->yy, next(it)->yy);
    }
    return result;
}

int dfs(int u)
{
    graph.cnt[u] = 1;
    graph.con[u] = true;

    for (auto &pr : graph.col[u])
    {
        auto &[col, vec] = pr;
        graph.con[u] &= vec.size() == 1;

        for (int v : vec)
        {
            int cnv = dfs(v);
            if (cnv == -1)
            {
                graph.con[u] = false;
            }
            else
            {
                graph.cnt[u] += cnv;
            }
            if (graph.con[u])
            {
                for (pii p : graph.srt[v])
                {
                    graph.con[u] &= insertAndCheck(graph.srt[u], p);
                }
            }
        }
    }
    graph.con[u] &= insertAndCheck(graph.srt[u], {graph.cnt[u], u});
    return graph.con[u] ? graph.cnt[u] : -1;
}

vector<int> beechtree(int n, int m, vector<int> P, vector<int> C)
{
    for (int i = 1; i < n; ++i)
    {
        int p = P[i];
        int c = C[i];
        if (!graph.col[p].count(c))
        {
            graph.col[p][c] = vector<int>();
        }
        graph.col[p][c].push_back(i);
    }
    dfs(0);
    vector<int> ans;
    for (int i = 0; i < n; ++i)
        ans.push_back(graph.con[i]);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19800 KB Output is correct
2 Correct 3 ms 19800 KB Output is correct
3 Correct 3 ms 19804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Correct 4 ms 19968 KB Output is correct
4 Correct 3 ms 20032 KB Output is correct
5 Correct 4 ms 19804 KB Output is correct
6 Correct 4 ms 19804 KB Output is correct
7 Correct 5 ms 19804 KB Output is correct
8 Correct 3 ms 19804 KB Output is correct
9 Correct 3 ms 19800 KB Output is correct
10 Correct 3 ms 19804 KB Output is correct
11 Correct 4 ms 19800 KB Output is correct
12 Correct 4 ms 19804 KB Output is correct
13 Correct 4 ms 19804 KB Output is correct
14 Correct 3 ms 20040 KB Output is correct
15 Correct 4 ms 19892 KB Output is correct
16 Correct 5 ms 19800 KB Output is correct
17 Correct 3 ms 20032 KB Output is correct
18 Correct 4 ms 19804 KB Output is correct
19 Correct 4 ms 20060 KB Output is correct
20 Correct 4 ms 19804 KB Output is correct
21 Correct 4 ms 19804 KB Output is correct
22 Correct 4 ms 19804 KB Output is correct
23 Correct 3 ms 19804 KB Output is correct
24 Correct 4 ms 19800 KB Output is correct
25 Correct 3 ms 19804 KB Output is correct
26 Correct 3 ms 19804 KB Output is correct
27 Correct 5 ms 20032 KB Output is correct
28 Correct 4 ms 19804 KB Output is correct
29 Correct 4 ms 19872 KB Output is correct
30 Correct 4 ms 20040 KB Output is correct
31 Correct 4 ms 19804 KB Output is correct
32 Correct 3 ms 19804 KB Output is correct
33 Correct 3 ms 19804 KB Output is correct
34 Correct 4 ms 19804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Correct 4 ms 19968 KB Output is correct
4 Correct 3 ms 20032 KB Output is correct
5 Correct 4 ms 19804 KB Output is correct
6 Correct 4 ms 19804 KB Output is correct
7 Correct 102 ms 77104 KB Output is correct
8 Correct 102 ms 76864 KB Output is correct
9 Correct 6 ms 20828 KB Output is correct
10 Correct 4 ms 20060 KB Output is correct
11 Correct 3 ms 19920 KB Output is correct
12 Correct 4 ms 19984 KB Output is correct
13 Correct 252 ms 114356 KB Output is correct
14 Correct 116 ms 68856 KB Output is correct
15 Correct 4 ms 20572 KB Output is correct
16 Correct 5 ms 20572 KB Output is correct
17 Execution timed out 2108 ms 958276 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19804 KB Output is correct
2 Correct 4 ms 20060 KB Output is correct
3 Correct 5 ms 20156 KB Output is correct
4 Correct 4 ms 20060 KB Output is correct
5 Correct 3 ms 19892 KB Output is correct
6 Correct 4 ms 20060 KB Output is correct
7 Correct 3 ms 19912 KB Output is correct
8 Correct 4 ms 20060 KB Output is correct
9 Correct 5 ms 20056 KB Output is correct
10 Correct 4 ms 20060 KB Output is correct
11 Correct 5 ms 20316 KB Output is correct
12 Correct 4 ms 20060 KB Output is correct
13 Correct 4 ms 20316 KB Output is correct
14 Correct 4 ms 20316 KB Output is correct
15 Correct 141 ms 47064 KB Output is correct
16 Correct 145 ms 47592 KB Output is correct
17 Correct 123 ms 47920 KB Output is correct
18 Correct 136 ms 48836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Correct 5 ms 19804 KB Output is correct
4 Correct 3 ms 19804 KB Output is correct
5 Correct 102 ms 77104 KB Output is correct
6 Correct 102 ms 76864 KB Output is correct
7 Correct 4 ms 20060 KB Output is correct
8 Correct 4 ms 20060 KB Output is correct
9 Correct 4 ms 20316 KB Output is correct
10 Correct 4 ms 20432 KB Output is correct
11 Correct 136 ms 66756 KB Output is correct
12 Correct 270 ms 65488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19800 KB Output is correct
2 Correct 3 ms 19800 KB Output is correct
3 Correct 3 ms 19804 KB Output is correct
4 Correct 4 ms 19804 KB Output is correct
5 Correct 4 ms 19804 KB Output is correct
6 Correct 4 ms 19968 KB Output is correct
7 Correct 3 ms 20032 KB Output is correct
8 Correct 4 ms 19804 KB Output is correct
9 Correct 4 ms 19804 KB Output is correct
10 Correct 5 ms 19804 KB Output is correct
11 Correct 3 ms 19804 KB Output is correct
12 Correct 3 ms 19800 KB Output is correct
13 Correct 3 ms 19804 KB Output is correct
14 Correct 4 ms 19800 KB Output is correct
15 Correct 4 ms 19804 KB Output is correct
16 Correct 4 ms 19804 KB Output is correct
17 Correct 3 ms 20040 KB Output is correct
18 Correct 4 ms 19892 KB Output is correct
19 Correct 5 ms 19800 KB Output is correct
20 Correct 3 ms 20032 KB Output is correct
21 Correct 4 ms 19804 KB Output is correct
22 Correct 4 ms 20060 KB Output is correct
23 Correct 4 ms 19804 KB Output is correct
24 Correct 4 ms 19804 KB Output is correct
25 Correct 4 ms 19804 KB Output is correct
26 Correct 3 ms 19804 KB Output is correct
27 Correct 4 ms 19800 KB Output is correct
28 Correct 3 ms 19804 KB Output is correct
29 Correct 3 ms 19804 KB Output is correct
30 Correct 5 ms 20032 KB Output is correct
31 Correct 4 ms 19804 KB Output is correct
32 Correct 4 ms 19872 KB Output is correct
33 Correct 4 ms 20040 KB Output is correct
34 Correct 4 ms 19804 KB Output is correct
35 Correct 3 ms 19804 KB Output is correct
36 Correct 3 ms 19804 KB Output is correct
37 Correct 4 ms 19804 KB Output is correct
38 Correct 6 ms 20828 KB Output is correct
39 Correct 4 ms 20060 KB Output is correct
40 Correct 3 ms 19920 KB Output is correct
41 Correct 4 ms 19984 KB Output is correct
42 Correct 3 ms 19804 KB Output is correct
43 Correct 4 ms 20060 KB Output is correct
44 Correct 5 ms 20156 KB Output is correct
45 Correct 4 ms 20060 KB Output is correct
46 Correct 3 ms 19892 KB Output is correct
47 Correct 4 ms 20060 KB Output is correct
48 Correct 3 ms 19912 KB Output is correct
49 Correct 4 ms 20060 KB Output is correct
50 Correct 5 ms 20056 KB Output is correct
51 Correct 4 ms 20060 KB Output is correct
52 Correct 4 ms 20060 KB Output is correct
53 Correct 4 ms 20060 KB Output is correct
54 Correct 4 ms 20060 KB Output is correct
55 Correct 4 ms 20060 KB Output is correct
56 Correct 4 ms 19944 KB Output is correct
57 Correct 6 ms 20032 KB Output is correct
58 Correct 4 ms 20060 KB Output is correct
59 Correct 5 ms 20032 KB Output is correct
60 Correct 4 ms 20060 KB Output is correct
61 Correct 5 ms 20060 KB Output is correct
62 Correct 4 ms 20060 KB Output is correct
63 Correct 4 ms 20092 KB Output is correct
64 Correct 4 ms 20060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Correct 5 ms 19804 KB Output is correct
4 Correct 3 ms 19804 KB Output is correct
5 Correct 3 ms 19800 KB Output is correct
6 Correct 3 ms 19804 KB Output is correct
7 Correct 4 ms 19800 KB Output is correct
8 Correct 4 ms 19804 KB Output is correct
9 Correct 4 ms 19804 KB Output is correct
10 Correct 3 ms 20040 KB Output is correct
11 Correct 4 ms 19892 KB Output is correct
12 Correct 5 ms 19800 KB Output is correct
13 Correct 3 ms 20032 KB Output is correct
14 Correct 4 ms 19804 KB Output is correct
15 Correct 4 ms 20060 KB Output is correct
16 Correct 4 ms 19804 KB Output is correct
17 Correct 4 ms 19804 KB Output is correct
18 Correct 4 ms 19804 KB Output is correct
19 Correct 3 ms 19804 KB Output is correct
20 Correct 4 ms 19800 KB Output is correct
21 Correct 3 ms 19804 KB Output is correct
22 Correct 3 ms 19804 KB Output is correct
23 Correct 5 ms 20032 KB Output is correct
24 Correct 4 ms 19804 KB Output is correct
25 Correct 273 ms 114256 KB Output is correct
26 Correct 130 ms 70996 KB Output is correct
27 Correct 68 ms 48212 KB Output is correct
28 Correct 4 ms 20572 KB Output is correct
29 Correct 257 ms 114264 KB Output is correct
30 Correct 20 ms 26204 KB Output is correct
31 Correct 6 ms 21340 KB Output is correct
32 Correct 7 ms 21084 KB Output is correct
33 Correct 5 ms 20572 KB Output is correct
34 Correct 7 ms 21084 KB Output is correct
35 Correct 6 ms 20828 KB Output is correct
36 Correct 5 ms 20572 KB Output is correct
37 Correct 60 ms 43832 KB Output is correct
38 Correct 22 ms 27484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19800 KB Output is correct
2 Correct 3 ms 19800 KB Output is correct
3 Correct 3 ms 19804 KB Output is correct
4 Correct 4 ms 19804 KB Output is correct
5 Correct 4 ms 19804 KB Output is correct
6 Correct 4 ms 19968 KB Output is correct
7 Correct 3 ms 20032 KB Output is correct
8 Correct 4 ms 19804 KB Output is correct
9 Correct 4 ms 19804 KB Output is correct
10 Correct 5 ms 19804 KB Output is correct
11 Correct 3 ms 19804 KB Output is correct
12 Correct 3 ms 19800 KB Output is correct
13 Correct 3 ms 19804 KB Output is correct
14 Correct 4 ms 19800 KB Output is correct
15 Correct 4 ms 19804 KB Output is correct
16 Correct 4 ms 19804 KB Output is correct
17 Correct 3 ms 20040 KB Output is correct
18 Correct 4 ms 19892 KB Output is correct
19 Correct 5 ms 19800 KB Output is correct
20 Correct 3 ms 20032 KB Output is correct
21 Correct 4 ms 19804 KB Output is correct
22 Correct 4 ms 20060 KB Output is correct
23 Correct 4 ms 19804 KB Output is correct
24 Correct 4 ms 19804 KB Output is correct
25 Correct 4 ms 19804 KB Output is correct
26 Correct 3 ms 19804 KB Output is correct
27 Correct 4 ms 19800 KB Output is correct
28 Correct 3 ms 19804 KB Output is correct
29 Correct 3 ms 19804 KB Output is correct
30 Correct 5 ms 20032 KB Output is correct
31 Correct 4 ms 19804 KB Output is correct
32 Correct 4 ms 19872 KB Output is correct
33 Correct 4 ms 20040 KB Output is correct
34 Correct 4 ms 19804 KB Output is correct
35 Correct 3 ms 19804 KB Output is correct
36 Correct 3 ms 19804 KB Output is correct
37 Correct 4 ms 19804 KB Output is correct
38 Correct 6 ms 20828 KB Output is correct
39 Correct 4 ms 20060 KB Output is correct
40 Correct 3 ms 19920 KB Output is correct
41 Correct 4 ms 19984 KB Output is correct
42 Correct 252 ms 114356 KB Output is correct
43 Correct 116 ms 68856 KB Output is correct
44 Correct 4 ms 20572 KB Output is correct
45 Correct 5 ms 20572 KB Output is correct
46 Correct 3 ms 19804 KB Output is correct
47 Correct 4 ms 20060 KB Output is correct
48 Correct 5 ms 20156 KB Output is correct
49 Correct 4 ms 20060 KB Output is correct
50 Correct 3 ms 19892 KB Output is correct
51 Correct 4 ms 20060 KB Output is correct
52 Correct 3 ms 19912 KB Output is correct
53 Correct 4 ms 20060 KB Output is correct
54 Correct 5 ms 20056 KB Output is correct
55 Correct 4 ms 20060 KB Output is correct
56 Correct 5 ms 20316 KB Output is correct
57 Correct 4 ms 20060 KB Output is correct
58 Correct 4 ms 20316 KB Output is correct
59 Correct 4 ms 20316 KB Output is correct
60 Correct 4 ms 20060 KB Output is correct
61 Correct 4 ms 20060 KB Output is correct
62 Correct 4 ms 20316 KB Output is correct
63 Correct 4 ms 20432 KB Output is correct
64 Correct 4 ms 20060 KB Output is correct
65 Correct 4 ms 20060 KB Output is correct
66 Correct 4 ms 19944 KB Output is correct
67 Correct 6 ms 20032 KB Output is correct
68 Correct 4 ms 20060 KB Output is correct
69 Correct 5 ms 20032 KB Output is correct
70 Correct 4 ms 20060 KB Output is correct
71 Correct 5 ms 20060 KB Output is correct
72 Correct 4 ms 20060 KB Output is correct
73 Correct 4 ms 20092 KB Output is correct
74 Correct 4 ms 20060 KB Output is correct
75 Correct 273 ms 114256 KB Output is correct
76 Correct 130 ms 70996 KB Output is correct
77 Correct 68 ms 48212 KB Output is correct
78 Correct 4 ms 20572 KB Output is correct
79 Correct 257 ms 114264 KB Output is correct
80 Correct 20 ms 26204 KB Output is correct
81 Correct 6 ms 21340 KB Output is correct
82 Correct 7 ms 21084 KB Output is correct
83 Correct 5 ms 20572 KB Output is correct
84 Correct 7 ms 21084 KB Output is correct
85 Correct 6 ms 20828 KB Output is correct
86 Correct 5 ms 20572 KB Output is correct
87 Correct 60 ms 43832 KB Output is correct
88 Correct 22 ms 27484 KB Output is correct
89 Correct 90 ms 52564 KB Output is correct
90 Correct 13 ms 24156 KB Output is correct
91 Correct 6 ms 20848 KB Output is correct
92 Correct 8 ms 20828 KB Output is correct
93 Correct 7 ms 20572 KB Output is correct
94 Correct 8 ms 20828 KB Output is correct
95 Correct 6 ms 20568 KB Output is correct
96 Correct 5 ms 20580 KB Output is correct
97 Correct 75 ms 43832 KB Output is correct
98 Correct 23 ms 27484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Correct 5 ms 19804 KB Output is correct
4 Correct 3 ms 19804 KB Output is correct
5 Correct 3 ms 19800 KB Output is correct
6 Correct 3 ms 19804 KB Output is correct
7 Correct 4 ms 19800 KB Output is correct
8 Correct 4 ms 19804 KB Output is correct
9 Correct 4 ms 19804 KB Output is correct
10 Correct 3 ms 20040 KB Output is correct
11 Correct 4 ms 19892 KB Output is correct
12 Correct 5 ms 19800 KB Output is correct
13 Correct 3 ms 20032 KB Output is correct
14 Correct 4 ms 19804 KB Output is correct
15 Correct 4 ms 20060 KB Output is correct
16 Correct 4 ms 19804 KB Output is correct
17 Correct 4 ms 19804 KB Output is correct
18 Correct 4 ms 19804 KB Output is correct
19 Correct 3 ms 19804 KB Output is correct
20 Correct 4 ms 19800 KB Output is correct
21 Correct 3 ms 19804 KB Output is correct
22 Correct 3 ms 19804 KB Output is correct
23 Correct 5 ms 20032 KB Output is correct
24 Correct 4 ms 19804 KB Output is correct
25 Correct 273 ms 114256 KB Output is correct
26 Correct 130 ms 70996 KB Output is correct
27 Correct 68 ms 48212 KB Output is correct
28 Correct 4 ms 20572 KB Output is correct
29 Correct 257 ms 114264 KB Output is correct
30 Correct 20 ms 26204 KB Output is correct
31 Correct 6 ms 21340 KB Output is correct
32 Correct 7 ms 21084 KB Output is correct
33 Correct 5 ms 20572 KB Output is correct
34 Correct 7 ms 21084 KB Output is correct
35 Correct 6 ms 20828 KB Output is correct
36 Correct 5 ms 20572 KB Output is correct
37 Correct 60 ms 43832 KB Output is correct
38 Correct 22 ms 27484 KB Output is correct
39 Execution timed out 2115 ms 989692 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19800 KB Output is correct
2 Correct 3 ms 19800 KB Output is correct
3 Correct 3 ms 19804 KB Output is correct
4 Correct 4 ms 19804 KB Output is correct
5 Correct 4 ms 19804 KB Output is correct
6 Correct 4 ms 19968 KB Output is correct
7 Correct 3 ms 20032 KB Output is correct
8 Correct 4 ms 19804 KB Output is correct
9 Correct 4 ms 19804 KB Output is correct
10 Correct 5 ms 19804 KB Output is correct
11 Correct 3 ms 19804 KB Output is correct
12 Correct 3 ms 19800 KB Output is correct
13 Correct 3 ms 19804 KB Output is correct
14 Correct 4 ms 19800 KB Output is correct
15 Correct 4 ms 19804 KB Output is correct
16 Correct 4 ms 19804 KB Output is correct
17 Correct 3 ms 20040 KB Output is correct
18 Correct 4 ms 19892 KB Output is correct
19 Correct 5 ms 19800 KB Output is correct
20 Correct 3 ms 20032 KB Output is correct
21 Correct 4 ms 19804 KB Output is correct
22 Correct 4 ms 20060 KB Output is correct
23 Correct 4 ms 19804 KB Output is correct
24 Correct 4 ms 19804 KB Output is correct
25 Correct 4 ms 19804 KB Output is correct
26 Correct 3 ms 19804 KB Output is correct
27 Correct 4 ms 19800 KB Output is correct
28 Correct 3 ms 19804 KB Output is correct
29 Correct 3 ms 19804 KB Output is correct
30 Correct 5 ms 20032 KB Output is correct
31 Correct 4 ms 19804 KB Output is correct
32 Correct 4 ms 19872 KB Output is correct
33 Correct 4 ms 20040 KB Output is correct
34 Correct 4 ms 19804 KB Output is correct
35 Correct 3 ms 19804 KB Output is correct
36 Correct 3 ms 19804 KB Output is correct
37 Correct 4 ms 19804 KB Output is correct
38 Correct 102 ms 77104 KB Output is correct
39 Correct 102 ms 76864 KB Output is correct
40 Correct 6 ms 20828 KB Output is correct
41 Correct 4 ms 20060 KB Output is correct
42 Correct 3 ms 19920 KB Output is correct
43 Correct 4 ms 19984 KB Output is correct
44 Correct 252 ms 114356 KB Output is correct
45 Correct 116 ms 68856 KB Output is correct
46 Correct 4 ms 20572 KB Output is correct
47 Correct 5 ms 20572 KB Output is correct
48 Execution timed out 2108 ms 958276 KB Time limit exceeded
49 Halted 0 ms 0 KB -