답안 #1068737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068737 2024-08-21T11:44:48 Z amirhoseinfar1385 참나무 (IOI23_beechtree) C++17
5 / 100
71 ms 38184 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 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;
        }
        st[P[i]].insert(all[i]);
    }
    vector<int>ret(n);
    ret[n-1]=ret[n-2]=1;
    for(int i=n-3;i>=0;i--){
        if(all[i+1]!=all[i+2]){
            ret[i]=0;
        }
        ret[i]=(1&ret[i+1]);
        if(all[i+1]!=all[i+2]){
            ret[i]=0;
        }
    }
    return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 14680 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 7 ms 14428 KB Output is correct
7 Incorrect 8 ms 14428 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 7 ms 14428 KB Output is correct
7 Correct 67 ms 38184 KB Output is correct
8 Correct 63 ms 37968 KB Output is correct
9 Correct 7 ms 14424 KB Output is correct
10 Correct 8 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 7 ms 14684 KB Output is correct
14 Correct 7 ms 14684 KB Output is correct
15 Correct 7 ms 14684 KB Output is correct
16 Correct 6 ms 14684 KB Output is correct
17 Correct 65 ms 37828 KB Output is correct
18 Correct 68 ms 37968 KB Output is correct
19 Correct 71 ms 37968 KB Output is correct
20 Correct 59 ms 37968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 14428 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Incorrect 8 ms 14428 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 14680 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Incorrect 8 ms 14428 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 14680 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Incorrect 8 ms 14428 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 14680 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -