답안 #917389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
917389 2024-01-28T04:37:42 Z abcvuitunggio 참나무 (IOI23_beechtree) C++17
9 / 100
88 ms 66708 KB
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
int n,m,bad[200001],d[200001],p[200001][20],dp[2001][2001],ch[200001];
vector <pair <int, int>> ke[200001];
vector <int> res;
void dfs(int u){
    for (auto [c,v]:ke[u]){
        dfs(v);
        bad[u]|=bad[v];
    }
}
int lca(int u, int v){
    u++,v++;
    if (d[u]<d[v])
        swap(u,v);
    int x=d[u]-d[v];
    for (int i=0;i<20;i++)
        if ((x>>i)&1)
            u=p[u][i];
    if (u==v)
        return u-1;
    for (int i=19;i>=0;i--)
        if (p[u][i]!=p[v][i]){
            u=p[u][i];
            v=p[v][i];
        }
    return p[u][0]-1;
}
vector <int> beechtree(int N, int M, vector<int> P, vector<int> C){
    n=N,m=M;
    for (int i=1;i<n;i++)
        ke[P[i]].push_back({C[i],i});
    for (int i=0;i<n;i++){
        sort(ke[i].begin(),ke[i].end());
        for (int j=1;j<ke[i].size();j++)
            if (ke[i][j].first==ke[i][j-1].first)
                bad[i]=1;
        p[i+1][0]=P[i]+1;
        d[i+1]=d[P[i]+1]+1;
        for (int j=1;j<20;j++)
            p[i+1][j]=p[p[i+1][j-1]][j-1];
    }
    for (int i=n-1;i>=0;i--)
        for (int j=n-1;j>i;j--){
            int u=i,v=j;
            if (ke[i].size()>ke[j].size())
                swap(u,v);
            for (auto [c,k]:ke[u])
                ch[c]=1;
            int cnt=0;
            for (auto [c,k]:ke[v])
                cnt+=ch[c];
            for (auto [c,k]:ke[u])
                ch[c]=0;
            if (cnt!=ke[u].size()){
                bad[lca(i,j)]=1;
                continue;
            }
            dp[i][j]=(ke[i].size()>ke[j].size()?1:(ke[i].size()<ke[j].size()?-1:0));
            if (!dp[i][j])
                for (int k=0;k<ke[i].size();k++){
                    int u=ke[i][k].second,v=ke[j][k].second;
                    if (u>v)
                        swap(u,v);
                    if (dp[u][v])
                        dp[i][j]=dp[u][v];
                }
        }
    for (int i=1;i<n;i++)
        for (int j=i+1;j<n;j++)
            if (dp[i][j]*dp[P[i]][P[j]]==-1)
                bad[lca(P[i],P[j])]=1;
    for (int i=1;i<n;i++)
        if (dp[0][i]<0)
            bad[0]=1;
    dfs(0);
    for (int i=0;i<n;i++)
        res.push_back(bad[i]^1);
    return res;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:36: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]
   36 |         for (int j=1;j<ke[i].size();j++)
      |                      ~^~~~~~~~~~~~~
beechtree.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |             if (cnt!=ke[u].size()){
      |                 ~~~^~~~~~~~~~~~~~
beechtree.cpp:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                 for (int k=0;k<ke[i].size();k++){
      |                              ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8804 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 3 ms 8796 KB Output is correct
10 Correct 3 ms 8796 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8816 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8792 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8792 KB Output is correct
27 Correct 2 ms 9048 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8952 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 3 ms 8792 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8804 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Runtime error 88 ms 66708 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10664 KB Output is correct
2 Correct 3 ms 10844 KB Output is correct
3 Correct 3 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 3 ms 10844 KB Output is correct
6 Correct 3 ms 10848 KB Output is correct
7 Correct 3 ms 10848 KB Output is correct
8 Correct 3 ms 10844 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 3 ms 10844 KB Output is correct
11 Correct 8 ms 19036 KB Output is correct
12 Correct 6 ms 16988 KB Output is correct
13 Correct 6 ms 16988 KB Output is correct
14 Correct 7 ms 16988 KB Output is correct
15 Runtime error 56 ms 40600 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Runtime error 88 ms 66708 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8804 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 3 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8816 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8792 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 3 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 9048 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8952 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 3 ms 8792 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 4 ms 10664 KB Output is correct
39 Correct 3 ms 10844 KB Output is correct
40 Correct 3 ms 10844 KB Output is correct
41 Correct 2 ms 10844 KB Output is correct
42 Correct 3 ms 10844 KB Output is correct
43 Correct 3 ms 10848 KB Output is correct
44 Correct 3 ms 10848 KB Output is correct
45 Correct 3 ms 10844 KB Output is correct
46 Correct 2 ms 8796 KB Output is correct
47 Correct 3 ms 10844 KB Output is correct
48 Correct 3 ms 10844 KB Output is correct
49 Correct 3 ms 10844 KB Output is correct
50 Correct 3 ms 10844 KB Output is correct
51 Correct 3 ms 10844 KB Output is correct
52 Correct 3 ms 10844 KB Output is correct
53 Correct 3 ms 10840 KB Output is correct
54 Correct 4 ms 10844 KB Output is correct
55 Incorrect 3 ms 10844 KB 2nd lines differ - on the 82nd token, expected: '0', found: '1'
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 3 ms 8796 KB Output is correct
7 Correct 2 ms 8792 KB Output is correct
8 Correct 3 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8816 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8792 KB Output is correct
23 Correct 2 ms 9048 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 19 ms 23284 KB Output is correct
26 Correct 18 ms 23276 KB Output is correct
27 Correct 35 ms 23128 KB Output is correct
28 Correct 84 ms 23124 KB Output is correct
29 Correct 18 ms 23256 KB Output is correct
30 Correct 73 ms 23288 KB Output is correct
31 Correct 17 ms 23128 KB Output is correct
32 Incorrect 30 ms 23132 KB 2nd lines differ - on the 802nd token, expected: '0', found: '1'
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8804 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 3 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8816 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8792 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 3 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 9048 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8952 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 3 ms 8792 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 3 ms 10844 KB Output is correct
39 Correct 3 ms 10844 KB Output is correct
40 Correct 3 ms 10844 KB Output is correct
41 Correct 3 ms 10844 KB Output is correct
42 Correct 4 ms 10664 KB Output is correct
43 Correct 3 ms 10844 KB Output is correct
44 Correct 3 ms 10844 KB Output is correct
45 Correct 2 ms 10844 KB Output is correct
46 Correct 3 ms 10844 KB Output is correct
47 Correct 3 ms 10848 KB Output is correct
48 Correct 3 ms 10848 KB Output is correct
49 Correct 3 ms 10844 KB Output is correct
50 Correct 2 ms 8796 KB Output is correct
51 Correct 3 ms 10844 KB Output is correct
52 Correct 8 ms 19036 KB Output is correct
53 Correct 6 ms 16988 KB Output is correct
54 Correct 6 ms 16988 KB Output is correct
55 Correct 7 ms 16988 KB Output is correct
56 Correct 3 ms 10844 KB Output is correct
57 Correct 3 ms 10840 KB Output is correct
58 Correct 4 ms 10844 KB Output is correct
59 Incorrect 3 ms 10844 KB 2nd lines differ - on the 82nd token, expected: '0', found: '1'
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 3 ms 8796 KB Output is correct
7 Correct 2 ms 8792 KB Output is correct
8 Correct 3 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8816 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8792 KB Output is correct
23 Correct 2 ms 9048 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 19 ms 23284 KB Output is correct
26 Correct 18 ms 23276 KB Output is correct
27 Correct 35 ms 23128 KB Output is correct
28 Correct 84 ms 23124 KB Output is correct
29 Correct 18 ms 23256 KB Output is correct
30 Correct 73 ms 23288 KB Output is correct
31 Correct 17 ms 23128 KB Output is correct
32 Incorrect 30 ms 23132 KB 2nd lines differ - on the 802nd token, expected: '0', found: '1'
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8804 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 3 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8816 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8792 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 3 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 9048 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8952 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 3 ms 8792 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Runtime error 88 ms 66708 KB Execution killed with signal 11
39 Halted 0 ms 0 KB -