Submission #922699

# Submission time Handle Problem Language Result Execution time Memory
922699 2024-02-06T03:20:06 Z abcvuitunggio Beech Tree (IOI23_beechtree) C++17
9 / 100
85 ms 68976 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 (u>v){
                        swap(u,v);
                        ch=-1;
                    }
                    if (dp[u][v])
                        dp[i][j]=dp[u][v]*ch;
                }
        }
    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++){
      |                              ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 3 ms 8796 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 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 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 8820 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 9052 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 9048 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 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 8792 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8792 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8792 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 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 8796 KB Output is correct
7 Runtime error 83 ms 68976 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 3 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 9 ms 17276 KB Output is correct
12 Correct 6 ms 15452 KB Output is correct
13 Correct 7 ms 15708 KB Output is correct
14 Correct 9 ms 16220 KB Output is correct
15 Runtime error 46 ms 38228 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 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Runtime error 83 ms 68976 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 3 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 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 8796 KB Output is correct
12 Correct 2 ms 8820 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 9052 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 9048 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 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8792 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8792 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8792 KB Output is correct
38 Correct 2 ms 10844 KB Output is correct
39 Correct 2 ms 10840 KB Output is correct
40 Correct 2 ms 10840 KB Output is correct
41 Correct 2 ms 10844 KB Output is correct
42 Correct 2 ms 10844 KB Output is correct
43 Correct 2 ms 10844 KB Output is correct
44 Correct 3 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 10844 KB Output is correct
50 Correct 2 ms 10840 KB Output is correct
51 Correct 3 ms 10840 KB Output is correct
52 Correct 3 ms 10844 KB Output is correct
53 Correct 2 ms 10840 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 2 ms 10864 KB Output is correct
58 Incorrect 2 ms 10844 KB 2nd lines differ - on the 78th token, expected: '0', found: '1'
59 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 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8820 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 9052 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 9048 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 8796 KB Output is correct
25 Correct 20 ms 22364 KB Output is correct
26 Correct 25 ms 22360 KB Output is correct
27 Correct 38 ms 22356 KB Output is correct
28 Correct 85 ms 22356 KB Output is correct
29 Correct 20 ms 22364 KB Output is correct
30 Correct 74 ms 22356 KB Output is correct
31 Correct 18 ms 22364 KB Output is correct
32 Incorrect 32 ms 22364 KB 2nd lines differ - on the 833rd token, expected: '0', found: '1'
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 3 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 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 8796 KB Output is correct
12 Correct 2 ms 8820 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 9052 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 9048 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 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8792 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8792 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8792 KB Output is correct
38 Correct 2 ms 10844 KB Output is correct
39 Correct 2 ms 10844 KB Output is correct
40 Correct 2 ms 10840 KB Output is correct
41 Correct 3 ms 10840 KB Output is correct
42 Correct 2 ms 10844 KB Output is correct
43 Correct 2 ms 10840 KB Output is correct
44 Correct 2 ms 10840 KB Output is correct
45 Correct 2 ms 10844 KB Output is correct
46 Correct 2 ms 10844 KB Output is correct
47 Correct 2 ms 10844 KB Output is correct
48 Correct 3 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 9 ms 17276 KB Output is correct
53 Correct 6 ms 15452 KB Output is correct
54 Correct 7 ms 15708 KB Output is correct
55 Correct 9 ms 16220 KB Output is correct
56 Correct 3 ms 10844 KB Output is correct
57 Correct 2 ms 10840 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 2 ms 10864 KB Output is correct
62 Incorrect 2 ms 10844 KB 2nd lines differ - on the 78th token, expected: '0', found: '1'
63 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 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8820 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 9052 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 9048 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 8796 KB Output is correct
25 Correct 20 ms 22364 KB Output is correct
26 Correct 25 ms 22360 KB Output is correct
27 Correct 38 ms 22356 KB Output is correct
28 Correct 85 ms 22356 KB Output is correct
29 Correct 20 ms 22364 KB Output is correct
30 Correct 74 ms 22356 KB Output is correct
31 Correct 18 ms 22364 KB Output is correct
32 Incorrect 32 ms 22364 KB 2nd lines differ - on the 833rd token, expected: '0', found: '1'
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 3 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 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 8796 KB Output is correct
12 Correct 2 ms 8820 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 9052 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 9048 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 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8792 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8792 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8792 KB Output is correct
38 Runtime error 83 ms 68976 KB Execution killed with signal 11
39 Halted 0 ms 0 KB -