Submission #1068499

# Submission time Handle Problem Language Result Execution time Memory
1068499 2024-08-21T10:18:31 Z amirhoseinfar1385 Beech Tree (IOI23_beechtree) C++17
0 / 100
2000 ms 81156 KB
#include "beechtree.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
int n,m,all[maxn],dp[maxn],vas[maxn],nist[maxn],sz[maxn],tof[maxn];
set<int>st[maxn];
vector<int>adj[maxn];

int dfsch2(int u){
    int ret=dp[u];
    for(auto x:adj[u]){
        int fake=dfsch2(x);
        if(fake==1&&dp[u]==0){
      //      if(u==2){
        //        cout<<"wtf"<<endl;
          //  }
            nist[u]=1;
            ret|=fake;
        }
    }
    return ret;
}

set<int> dfsch(int u){
    set<int>ret;
    ret.insert(dp[u]);
    for(auto x:adj[u]){
        set<int>fake=dfsch(x);
        for(auto x:fake){
            ret.insert(x);
        }
    }
    if(ret.count(1)==1&&1==ret.count(2)){
      //  if(u==2){
        //    cout<<"wtf"<<endl;
        //}
        nist[u]=1;
    }
    return ret;
}

void check(int cl){
    for(int i=1;i<=m;i++){
        for(int j=0;j<n;j++){
            dp[j]=0;
            if(st[j].count(cl)==1){
                dp[j]+=1;
            }
            if(st[j].count(i)==1){
                dp[j]+=2;
            }
        }
        dfsch(0);
    }
    for(int j=0;j<n;j++){
        dp[j]=st[j].count(cl);
    }
    dfsch2(0);
}

int calc(int u){
    sz[u]=1;
    int ret=nist[u];
    int cnt=0;
    for(auto x:adj[u]){
        ret|=calc(x);
        sz[u]+=sz[x];
        if(sz[x]>1){
            cnt++;
            tof[u]=all[x];
            if(tof[x]!=-1&&tof[x]!=tof[u]){
                ret=1;
            }
        }
    }
    if(cnt>1){
        ret=1;
    }
    if(ret){
        vas[u]=1;
    }
    return ret;
}

std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C)
{
    n=N;
    m=M;
    for(int i=0;i<n;i++){
        tof[i]=-1;
    }
    for(int i=1;i<=n-1;i++){
        adj[P[i]].push_back(i);
        all[i]=C[i];
        if(st[P[i]].count(all[i])!=0){
            nist[P[i]]=1;
        //    if(P[i]==2){
          //      cout<<"wtf"<<endl;
            //}
        }
        st[P[i]].insert(all[i]);
    }
    for(int i=1;i<=m;i++){
        check(i);
    }
    calc(0);
    vector<int>ret(n);
    for(int i=0;i<n;i++){
        ret[i]=(1^vas[i]);
    }
    return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14400 KB Output is correct
2 Incorrect 7 ms 14512 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14360 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 74 ms 14540 KB Output is correct
4 Correct 75 ms 14532 KB Output is correct
5 Correct 77 ms 14540 KB Output is correct
6 Correct 72 ms 14548 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 7 ms 14428 KB Output is correct
9 Correct 7 ms 14364 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 7 ms 14428 KB Output is correct
15 Correct 7 ms 14428 KB Output is correct
16 Correct 7 ms 14428 KB Output is correct
17 Correct 7 ms 14528 KB Output is correct
18 Correct 6 ms 14536 KB Output is correct
19 Correct 6 ms 14428 KB Output is correct
20 Correct 6 ms 14428 KB Output is correct
21 Correct 6 ms 14428 KB Output is correct
22 Correct 6 ms 14508 KB Output is correct
23 Correct 6 ms 14552 KB Output is correct
24 Correct 7 ms 14436 KB Output is correct
25 Correct 7 ms 14428 KB Output is correct
26 Correct 6 ms 14500 KB Output is correct
27 Correct 6 ms 14692 KB Output is correct
28 Incorrect 6 ms 14440 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14360 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 74 ms 14540 KB Output is correct
4 Correct 75 ms 14532 KB Output is correct
5 Correct 77 ms 14540 KB Output is correct
6 Correct 72 ms 14548 KB Output is correct
7 Execution timed out 2089 ms 81156 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 944 ms 14536 KB Output is correct
2 Correct 1531 ms 14540 KB Output is correct
3 Correct 1087 ms 14544 KB Output is correct
4 Correct 1103 ms 14536 KB Output is correct
5 Correct 1124 ms 14428 KB Output is correct
6 Correct 1091 ms 14540 KB Output is correct
7 Correct 1008 ms 14532 KB Output is correct
8 Correct 972 ms 14536 KB Output is correct
9 Incorrect 831 ms 14424 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14360 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Execution timed out 2089 ms 81156 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14400 KB Output is correct
2 Incorrect 7 ms 14512 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14360 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14364 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 7 ms 14428 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 7 ms 14528 KB Output is correct
14 Correct 6 ms 14536 KB Output is correct
15 Correct 6 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14508 KB Output is correct
19 Correct 6 ms 14552 KB Output is correct
20 Correct 7 ms 14436 KB Output is correct
21 Correct 7 ms 14428 KB Output is correct
22 Correct 6 ms 14500 KB Output is correct
23 Correct 6 ms 14692 KB Output is correct
24 Incorrect 6 ms 14440 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14400 KB Output is correct
2 Incorrect 7 ms 14512 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14360 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14364 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 7 ms 14428 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 7 ms 14528 KB Output is correct
14 Correct 6 ms 14536 KB Output is correct
15 Correct 6 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14508 KB Output is correct
19 Correct 6 ms 14552 KB Output is correct
20 Correct 7 ms 14436 KB Output is correct
21 Correct 7 ms 14428 KB Output is correct
22 Correct 6 ms 14500 KB Output is correct
23 Correct 6 ms 14692 KB Output is correct
24 Incorrect 6 ms 14440 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14400 KB Output is correct
2 Incorrect 7 ms 14512 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -