Submission #922707

# Submission time Handle Problem Language Result Execution time Memory
922707 2024-02-06T03:38:57 Z abcvuitunggio Beech Tree (IOI23_beechtree) C++17
49 / 100
151 ms 69060 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,ch=1;
                    if (dp[u][v])
                        dp[i][j]=dp[u][v];
                }
            dp[j][i]=-dp[i][j];
        }
    for (int i=1;i<n;i++)
        for (int j=i+1;j<n;j++)
            if (C[i]==C[j]&&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++){
      |                              ~^~~~~~~~~~~~~
beechtree.cpp:63:61: warning: unused variable 'ch' [-Wunused-variable]
   63 |                     int u=ke[i][k].second,v=ke[j][k].second,ch=1;
      |                                                             ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8816 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 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 3 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 8796 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 8804 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 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 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8804 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8828 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Runtime error 100 ms 69060 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 3 ms 10844 KB Output is correct
3 Correct 3 ms 10840 KB Output is correct
4 Correct 3 ms 10840 KB Output is correct
5 Correct 3 ms 10868 KB Output is correct
6 Correct 3 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 8 ms 19036 KB Output is correct
12 Correct 6 ms 16984 KB Output is correct
13 Correct 10 ms 16988 KB Output is correct
14 Correct 8 ms 16984 KB Output is correct
15 Runtime error 46 ms 41552 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 3 ms 8816 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Runtime error 100 ms 69060 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 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 8792 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 3 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 8796 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 3 ms 8796 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 2 ms 8796 KB Output is correct
27 Correct 2 ms 8804 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8804 KB Output is correct
35 Correct 2 ms 8796 KB Output is correct
36 Correct 2 ms 8828 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 2 ms 10840 KB Output is correct
39 Correct 3 ms 10844 KB Output is correct
40 Correct 3 ms 10840 KB Output is correct
41 Correct 3 ms 10840 KB Output is correct
42 Correct 3 ms 10868 KB Output is correct
43 Correct 3 ms 10844 KB Output is correct
44 Correct 2 ms 10844 KB Output is correct
45 Correct 2 ms 10840 KB Output is correct
46 Correct 2 ms 8796 KB Output is correct
47 Correct 2 ms 10844 KB Output is correct
48 Correct 2 ms 10844 KB Output is correct
49 Correct 2 ms 10856 KB Output is correct
50 Correct 3 ms 10840 KB Output is correct
51 Correct 2 ms 10844 KB Output is correct
52 Correct 2 ms 10844 KB Output is correct
53 Correct 3 ms 10844 KB Output is correct
54 Correct 2 ms 10844 KB Output is correct
55 Correct 2 ms 10844 KB Output is correct
56 Correct 2 ms 10840 KB Output is correct
57 Correct 3 ms 10844 KB Output is correct
58 Correct 2 ms 10840 KB Output is correct
59 Correct 2 ms 10844 KB Output is correct
60 Correct 3 ms 11096 KB Output is correct
61 Correct 3 ms 10868 KB Output is correct
62 Correct 3 ms 10888 KB Output is correct
63 Correct 3 ms 11008 KB Output is correct
64 Correct 4 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 3 ms 8816 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 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 3 ms 8796 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 2 ms 8796 KB Output is correct
20 Correct 2 ms 8804 KB Output is correct
21 Correct 2 ms 8796 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 32 ms 23384 KB Output is correct
26 Correct 28 ms 23156 KB Output is correct
27 Correct 44 ms 23124 KB Output is correct
28 Correct 98 ms 23280 KB Output is correct
29 Correct 23 ms 23296 KB Output is correct
30 Correct 75 ms 23292 KB Output is correct
31 Correct 18 ms 23132 KB Output is correct
32 Correct 36 ms 23388 KB Output is correct
33 Correct 51 ms 23268 KB Output is correct
34 Correct 20 ms 23128 KB Output is correct
35 Correct 20 ms 23160 KB Output is correct
36 Correct 26 ms 23128 KB Output is correct
37 Correct 18 ms 23160 KB Output is correct
38 Correct 79 ms 23120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 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 8792 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 3 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 8796 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 3 ms 8796 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 2 ms 8796 KB Output is correct
27 Correct 2 ms 8804 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8804 KB Output is correct
35 Correct 2 ms 8796 KB Output is correct
36 Correct 2 ms 8828 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 2 ms 10844 KB Output is correct
39 Correct 2 ms 10856 KB Output is correct
40 Correct 3 ms 10840 KB Output is correct
41 Correct 2 ms 10844 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
43 Correct 3 ms 10844 KB Output is correct
44 Correct 3 ms 10840 KB Output is correct
45 Correct 3 ms 10840 KB Output is correct
46 Correct 3 ms 10868 KB Output is correct
47 Correct 3 ms 10844 KB Output is correct
48 Correct 2 ms 10844 KB Output is correct
49 Correct 2 ms 10840 KB Output is correct
50 Correct 2 ms 8796 KB Output is correct
51 Correct 2 ms 10844 KB Output is correct
52 Correct 8 ms 19036 KB Output is correct
53 Correct 6 ms 16984 KB Output is correct
54 Correct 10 ms 16988 KB Output is correct
55 Correct 8 ms 16984 KB Output is correct
56 Correct 2 ms 10844 KB Output is correct
57 Correct 3 ms 10844 KB Output is correct
58 Correct 2 ms 10844 KB Output is correct
59 Correct 2 ms 10844 KB Output is correct
60 Correct 2 ms 10840 KB Output is correct
61 Correct 3 ms 10844 KB Output is correct
62 Correct 2 ms 10840 KB Output is correct
63 Correct 2 ms 10844 KB Output is correct
64 Correct 3 ms 11096 KB Output is correct
65 Correct 3 ms 10868 KB Output is correct
66 Correct 3 ms 10888 KB Output is correct
67 Correct 3 ms 11008 KB Output is correct
68 Correct 4 ms 10840 KB Output is correct
69 Correct 32 ms 23384 KB Output is correct
70 Correct 28 ms 23156 KB Output is correct
71 Correct 44 ms 23124 KB Output is correct
72 Correct 98 ms 23280 KB Output is correct
73 Correct 23 ms 23296 KB Output is correct
74 Correct 75 ms 23292 KB Output is correct
75 Correct 18 ms 23132 KB Output is correct
76 Correct 36 ms 23388 KB Output is correct
77 Correct 51 ms 23268 KB Output is correct
78 Correct 20 ms 23128 KB Output is correct
79 Correct 20 ms 23160 KB Output is correct
80 Correct 26 ms 23128 KB Output is correct
81 Correct 18 ms 23160 KB Output is correct
82 Correct 79 ms 23120 KB Output is correct
83 Correct 31 ms 23388 KB Output is correct
84 Correct 26 ms 23284 KB Output is correct
85 Correct 112 ms 23296 KB Output is correct
86 Correct 121 ms 23124 KB Output is correct
87 Correct 36 ms 23128 KB Output is correct
88 Correct 14 ms 23132 KB Output is correct
89 Correct 22 ms 23300 KB Output is correct
90 Correct 151 ms 23120 KB Output is correct
91 Correct 20 ms 23280 KB Output is correct
92 Correct 54 ms 23276 KB Output is correct
93 Correct 62 ms 23120 KB Output is correct
94 Correct 18 ms 23128 KB Output is correct
95 Correct 35 ms 23276 KB Output is correct
96 Correct 30 ms 23124 KB Output is correct
97 Correct 29 ms 23132 KB Output is correct
98 Correct 113 ms 23280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 3 ms 8816 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 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 3 ms 8796 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 2 ms 8796 KB Output is correct
20 Correct 2 ms 8804 KB Output is correct
21 Correct 2 ms 8796 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 32 ms 23384 KB Output is correct
26 Correct 28 ms 23156 KB Output is correct
27 Correct 44 ms 23124 KB Output is correct
28 Correct 98 ms 23280 KB Output is correct
29 Correct 23 ms 23296 KB Output is correct
30 Correct 75 ms 23292 KB Output is correct
31 Correct 18 ms 23132 KB Output is correct
32 Correct 36 ms 23388 KB Output is correct
33 Correct 51 ms 23268 KB Output is correct
34 Correct 20 ms 23128 KB Output is correct
35 Correct 20 ms 23160 KB Output is correct
36 Correct 26 ms 23128 KB Output is correct
37 Correct 18 ms 23160 KB Output is correct
38 Correct 79 ms 23120 KB Output is correct
39 Runtime error 80 ms 68200 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 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 8792 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 3 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 8796 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 3 ms 8796 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 2 ms 8796 KB Output is correct
27 Correct 2 ms 8804 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8804 KB Output is correct
35 Correct 2 ms 8796 KB Output is correct
36 Correct 2 ms 8828 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Runtime error 100 ms 69060 KB Execution killed with signal 11
39 Halted 0 ms 0 KB -