답안 #841621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841621 2023-09-01T18:44:26 Z Enchom 참나무 (IOI23_beechtree) C++17
58 / 100
2000 ms 588188 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];
    vector<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() || graph.cnt[vec[0]] > graph.cnt[it->yy[0]])
        {
            return false;
        }
    }
    return true;
}

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;
            }
            for (pii p : graph.srt[v])
            {
                graph.srt[u].push_back(p);
            }
        }
    }
    graph.srt[u].push_back({graph.cnt[u], u});
    sort(all(graph.srt[u]));

    for (int i = 0; i < graph.srt[u].size() - 1; ++i)
    {
        graph.con[u] = graph.con[u] & check(graph.srt[u][i].yy, graph.srt[u][i + 1].yy);
    }
    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;
}

Compilation message

beechtree.cpp: In function 'int dfs(int)':
beechtree.cpp:64:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for (int i = 0; i < graph.srt[u].size() - 1; ++i)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 15192 KB Output is correct
2 Correct 3 ms 15192 KB Output is correct
3 Correct 3 ms 15196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 15192 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15276 KB Output is correct
4 Correct 3 ms 15196 KB Output is correct
5 Correct 3 ms 15196 KB Output is correct
6 Correct 3 ms 15196 KB Output is correct
7 Correct 3 ms 15196 KB Output is correct
8 Correct 4 ms 15196 KB Output is correct
9 Correct 3 ms 15196 KB Output is correct
10 Correct 3 ms 15196 KB Output is correct
11 Correct 3 ms 15196 KB Output is correct
12 Correct 3 ms 15196 KB Output is correct
13 Correct 3 ms 15196 KB Output is correct
14 Correct 3 ms 15196 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15196 KB Output is correct
17 Correct 3 ms 15196 KB Output is correct
18 Correct 4 ms 15196 KB Output is correct
19 Correct 3 ms 15196 KB Output is correct
20 Correct 3 ms 15196 KB Output is correct
21 Correct 3 ms 15196 KB Output is correct
22 Correct 3 ms 15196 KB Output is correct
23 Correct 3 ms 15196 KB Output is correct
24 Correct 4 ms 15196 KB Output is correct
25 Correct 3 ms 15196 KB Output is correct
26 Correct 3 ms 15196 KB Output is correct
27 Correct 4 ms 15196 KB Output is correct
28 Correct 3 ms 15196 KB Output is correct
29 Correct 3 ms 15196 KB Output is correct
30 Correct 3 ms 15196 KB Output is correct
31 Correct 3 ms 15196 KB Output is correct
32 Correct 3 ms 15196 KB Output is correct
33 Correct 3 ms 15196 KB Output is correct
34 Correct 3 ms 15196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 15192 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15276 KB Output is correct
4 Correct 3 ms 15196 KB Output is correct
5 Correct 3 ms 15196 KB Output is correct
6 Correct 3 ms 15196 KB Output is correct
7 Execution timed out 2111 ms 254608 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 15192 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15196 KB Output is correct
4 Correct 3 ms 15196 KB Output is correct
5 Correct 3 ms 15196 KB Output is correct
6 Correct 4 ms 15196 KB Output is correct
7 Correct 3 ms 15196 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 3 ms 15196 KB Output is correct
10 Correct 3 ms 15196 KB Output is correct
11 Correct 3 ms 15452 KB Output is correct
12 Correct 3 ms 15452 KB Output is correct
13 Correct 4 ms 15452 KB Output is correct
14 Correct 4 ms 15452 KB Output is correct
15 Correct 101 ms 35616 KB Output is correct
16 Correct 89 ms 34248 KB Output is correct
17 Correct 86 ms 34592 KB Output is correct
18 Correct 102 ms 35340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 15192 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15196 KB Output is correct
4 Correct 4 ms 15196 KB Output is correct
5 Execution timed out 2111 ms 254608 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 15192 KB Output is correct
2 Correct 3 ms 15192 KB Output is correct
3 Correct 3 ms 15196 KB Output is correct
4 Correct 3 ms 15192 KB Output is correct
5 Correct 3 ms 15196 KB Output is correct
6 Correct 3 ms 15276 KB Output is correct
7 Correct 3 ms 15196 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 3 ms 15196 KB Output is correct
10 Correct 3 ms 15196 KB Output is correct
11 Correct 4 ms 15196 KB Output is correct
12 Correct 3 ms 15196 KB Output is correct
13 Correct 3 ms 15196 KB Output is correct
14 Correct 3 ms 15196 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15196 KB Output is correct
17 Correct 3 ms 15196 KB Output is correct
18 Correct 3 ms 15196 KB Output is correct
19 Correct 3 ms 15196 KB Output is correct
20 Correct 3 ms 15196 KB Output is correct
21 Correct 4 ms 15196 KB Output is correct
22 Correct 3 ms 15196 KB Output is correct
23 Correct 3 ms 15196 KB Output is correct
24 Correct 3 ms 15196 KB Output is correct
25 Correct 3 ms 15196 KB Output is correct
26 Correct 3 ms 15196 KB Output is correct
27 Correct 4 ms 15196 KB Output is correct
28 Correct 3 ms 15196 KB Output is correct
29 Correct 3 ms 15196 KB Output is correct
30 Correct 4 ms 15196 KB Output is correct
31 Correct 3 ms 15196 KB Output is correct
32 Correct 3 ms 15196 KB Output is correct
33 Correct 3 ms 15196 KB Output is correct
34 Correct 3 ms 15196 KB Output is correct
35 Correct 3 ms 15196 KB Output is correct
36 Correct 3 ms 15196 KB Output is correct
37 Correct 3 ms 15196 KB Output is correct
38 Correct 3 ms 15192 KB Output is correct
39 Correct 3 ms 15196 KB Output is correct
40 Correct 3 ms 15196 KB Output is correct
41 Correct 3 ms 15196 KB Output is correct
42 Correct 3 ms 15196 KB Output is correct
43 Correct 4 ms 15196 KB Output is correct
44 Correct 3 ms 15196 KB Output is correct
45 Correct 3 ms 15196 KB Output is correct
46 Correct 3 ms 15196 KB Output is correct
47 Correct 3 ms 15196 KB Output is correct
48 Correct 3 ms 15452 KB Output is correct
49 Correct 4 ms 15452 KB Output is correct
50 Correct 4 ms 15452 KB Output is correct
51 Correct 4 ms 15452 KB Output is correct
52 Correct 3 ms 15196 KB Output is correct
53 Correct 3 ms 15604 KB Output is correct
54 Correct 4 ms 15196 KB Output is correct
55 Correct 3 ms 15196 KB Output is correct
56 Correct 3 ms 15196 KB Output is correct
57 Correct 3 ms 15196 KB Output is correct
58 Correct 3 ms 15196 KB Output is correct
59 Correct 3 ms 15196 KB Output is correct
60 Correct 3 ms 15196 KB Output is correct
61 Correct 4 ms 15196 KB Output is correct
62 Correct 4 ms 15340 KB Output is correct
63 Correct 3 ms 15196 KB Output is correct
64 Correct 3 ms 15196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 15192 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15196 KB Output is correct
4 Correct 4 ms 15196 KB Output is correct
5 Correct 3 ms 15196 KB Output is correct
6 Correct 3 ms 15196 KB Output is correct
7 Correct 3 ms 15196 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 3 ms 15196 KB Output is correct
10 Correct 3 ms 15196 KB Output is correct
11 Correct 3 ms 15196 KB Output is correct
12 Correct 3 ms 15196 KB Output is correct
13 Correct 3 ms 15196 KB Output is correct
14 Correct 4 ms 15196 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15196 KB Output is correct
17 Correct 3 ms 15196 KB Output is correct
18 Correct 3 ms 15196 KB Output is correct
19 Correct 3 ms 15196 KB Output is correct
20 Correct 4 ms 15196 KB Output is correct
21 Correct 3 ms 15196 KB Output is correct
22 Correct 3 ms 15196 KB Output is correct
23 Correct 4 ms 15196 KB Output is correct
24 Correct 3 ms 15196 KB Output is correct
25 Correct 54 ms 35868 KB Output is correct
26 Correct 103 ms 35924 KB Output is correct
27 Correct 132 ms 35924 KB Output is correct
28 Correct 174 ms 35924 KB Output is correct
29 Correct 53 ms 35972 KB Output is correct
30 Correct 10 ms 17756 KB Output is correct
31 Correct 5 ms 15708 KB Output is correct
32 Correct 5 ms 15708 KB Output is correct
33 Correct 7 ms 15964 KB Output is correct
34 Correct 4 ms 15708 KB Output is correct
35 Correct 4 ms 15708 KB Output is correct
36 Correct 5 ms 15708 KB Output is correct
37 Correct 18 ms 20828 KB Output is correct
38 Correct 11 ms 17756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 15192 KB Output is correct
2 Correct 3 ms 15192 KB Output is correct
3 Correct 3 ms 15196 KB Output is correct
4 Correct 3 ms 15192 KB Output is correct
5 Correct 3 ms 15196 KB Output is correct
6 Correct 3 ms 15276 KB Output is correct
7 Correct 3 ms 15196 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 3 ms 15196 KB Output is correct
10 Correct 3 ms 15196 KB Output is correct
11 Correct 4 ms 15196 KB Output is correct
12 Correct 3 ms 15196 KB Output is correct
13 Correct 3 ms 15196 KB Output is correct
14 Correct 3 ms 15196 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15196 KB Output is correct
17 Correct 3 ms 15196 KB Output is correct
18 Correct 3 ms 15196 KB Output is correct
19 Correct 3 ms 15196 KB Output is correct
20 Correct 3 ms 15196 KB Output is correct
21 Correct 4 ms 15196 KB Output is correct
22 Correct 3 ms 15196 KB Output is correct
23 Correct 3 ms 15196 KB Output is correct
24 Correct 3 ms 15196 KB Output is correct
25 Correct 3 ms 15196 KB Output is correct
26 Correct 3 ms 15196 KB Output is correct
27 Correct 4 ms 15196 KB Output is correct
28 Correct 3 ms 15196 KB Output is correct
29 Correct 3 ms 15196 KB Output is correct
30 Correct 4 ms 15196 KB Output is correct
31 Correct 3 ms 15196 KB Output is correct
32 Correct 3 ms 15196 KB Output is correct
33 Correct 3 ms 15196 KB Output is correct
34 Correct 3 ms 15196 KB Output is correct
35 Correct 3 ms 15196 KB Output is correct
36 Correct 3 ms 15196 KB Output is correct
37 Correct 3 ms 15196 KB Output is correct
38 Correct 3 ms 15452 KB Output is correct
39 Correct 4 ms 15452 KB Output is correct
40 Correct 4 ms 15452 KB Output is correct
41 Correct 4 ms 15452 KB Output is correct
42 Correct 3 ms 15192 KB Output is correct
43 Correct 3 ms 15196 KB Output is correct
44 Correct 3 ms 15196 KB Output is correct
45 Correct 3 ms 15196 KB Output is correct
46 Correct 3 ms 15196 KB Output is correct
47 Correct 4 ms 15196 KB Output is correct
48 Correct 3 ms 15196 KB Output is correct
49 Correct 3 ms 15196 KB Output is correct
50 Correct 3 ms 15196 KB Output is correct
51 Correct 3 ms 15196 KB Output is correct
52 Correct 3 ms 15452 KB Output is correct
53 Correct 3 ms 15452 KB Output is correct
54 Correct 4 ms 15452 KB Output is correct
55 Correct 4 ms 15452 KB Output is correct
56 Correct 3 ms 15196 KB Output is correct
57 Correct 3 ms 15604 KB Output is correct
58 Correct 4 ms 15196 KB Output is correct
59 Correct 3 ms 15196 KB Output is correct
60 Correct 3 ms 15196 KB Output is correct
61 Correct 3 ms 15196 KB Output is correct
62 Correct 3 ms 15196 KB Output is correct
63 Correct 3 ms 15196 KB Output is correct
64 Correct 3 ms 15196 KB Output is correct
65 Correct 4 ms 15196 KB Output is correct
66 Correct 4 ms 15340 KB Output is correct
67 Correct 3 ms 15196 KB Output is correct
68 Correct 3 ms 15196 KB Output is correct
69 Correct 54 ms 35868 KB Output is correct
70 Correct 103 ms 35924 KB Output is correct
71 Correct 132 ms 35924 KB Output is correct
72 Correct 174 ms 35924 KB Output is correct
73 Correct 53 ms 35972 KB Output is correct
74 Correct 10 ms 17756 KB Output is correct
75 Correct 5 ms 15708 KB Output is correct
76 Correct 5 ms 15708 KB Output is correct
77 Correct 7 ms 15964 KB Output is correct
78 Correct 4 ms 15708 KB Output is correct
79 Correct 4 ms 15708 KB Output is correct
80 Correct 5 ms 15708 KB Output is correct
81 Correct 18 ms 20828 KB Output is correct
82 Correct 11 ms 17756 KB Output is correct
83 Correct 58 ms 35820 KB Output is correct
84 Correct 106 ms 35924 KB Output is correct
85 Correct 175 ms 35980 KB Output is correct
86 Correct 181 ms 35808 KB Output is correct
87 Correct 12 ms 16988 KB Output is correct
88 Correct 6 ms 15708 KB Output is correct
89 Correct 21 ms 23132 KB Output is correct
90 Correct 8 ms 16732 KB Output is correct
91 Correct 5 ms 15708 KB Output is correct
92 Correct 5 ms 15708 KB Output is correct
93 Correct 8 ms 15964 KB Output is correct
94 Correct 5 ms 15708 KB Output is correct
95 Correct 4 ms 15708 KB Output is correct
96 Correct 6 ms 15708 KB Output is correct
97 Correct 18 ms 20828 KB Output is correct
98 Correct 11 ms 18012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 15192 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15196 KB Output is correct
4 Correct 4 ms 15196 KB Output is correct
5 Correct 3 ms 15196 KB Output is correct
6 Correct 3 ms 15196 KB Output is correct
7 Correct 3 ms 15196 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 3 ms 15196 KB Output is correct
10 Correct 3 ms 15196 KB Output is correct
11 Correct 3 ms 15196 KB Output is correct
12 Correct 3 ms 15196 KB Output is correct
13 Correct 3 ms 15196 KB Output is correct
14 Correct 4 ms 15196 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15196 KB Output is correct
17 Correct 3 ms 15196 KB Output is correct
18 Correct 3 ms 15196 KB Output is correct
19 Correct 3 ms 15196 KB Output is correct
20 Correct 4 ms 15196 KB Output is correct
21 Correct 3 ms 15196 KB Output is correct
22 Correct 3 ms 15196 KB Output is correct
23 Correct 4 ms 15196 KB Output is correct
24 Correct 3 ms 15196 KB Output is correct
25 Correct 54 ms 35868 KB Output is correct
26 Correct 103 ms 35924 KB Output is correct
27 Correct 132 ms 35924 KB Output is correct
28 Correct 174 ms 35924 KB Output is correct
29 Correct 53 ms 35972 KB Output is correct
30 Correct 10 ms 17756 KB Output is correct
31 Correct 5 ms 15708 KB Output is correct
32 Correct 5 ms 15708 KB Output is correct
33 Correct 7 ms 15964 KB Output is correct
34 Correct 4 ms 15708 KB Output is correct
35 Correct 4 ms 15708 KB Output is correct
36 Correct 5 ms 15708 KB Output is correct
37 Correct 18 ms 20828 KB Output is correct
38 Correct 11 ms 17756 KB Output is correct
39 Execution timed out 2073 ms 588188 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 15192 KB Output is correct
2 Correct 3 ms 15192 KB Output is correct
3 Correct 3 ms 15196 KB Output is correct
4 Correct 3 ms 15192 KB Output is correct
5 Correct 3 ms 15196 KB Output is correct
6 Correct 3 ms 15276 KB Output is correct
7 Correct 3 ms 15196 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 3 ms 15196 KB Output is correct
10 Correct 3 ms 15196 KB Output is correct
11 Correct 4 ms 15196 KB Output is correct
12 Correct 3 ms 15196 KB Output is correct
13 Correct 3 ms 15196 KB Output is correct
14 Correct 3 ms 15196 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15196 KB Output is correct
17 Correct 3 ms 15196 KB Output is correct
18 Correct 3 ms 15196 KB Output is correct
19 Correct 3 ms 15196 KB Output is correct
20 Correct 3 ms 15196 KB Output is correct
21 Correct 4 ms 15196 KB Output is correct
22 Correct 3 ms 15196 KB Output is correct
23 Correct 3 ms 15196 KB Output is correct
24 Correct 3 ms 15196 KB Output is correct
25 Correct 3 ms 15196 KB Output is correct
26 Correct 3 ms 15196 KB Output is correct
27 Correct 4 ms 15196 KB Output is correct
28 Correct 3 ms 15196 KB Output is correct
29 Correct 3 ms 15196 KB Output is correct
30 Correct 4 ms 15196 KB Output is correct
31 Correct 3 ms 15196 KB Output is correct
32 Correct 3 ms 15196 KB Output is correct
33 Correct 3 ms 15196 KB Output is correct
34 Correct 3 ms 15196 KB Output is correct
35 Correct 3 ms 15196 KB Output is correct
36 Correct 3 ms 15196 KB Output is correct
37 Correct 3 ms 15196 KB Output is correct
38 Execution timed out 2111 ms 254608 KB Time limit exceeded
39 Halted 0 ms 0 KB -