Submission #1016108

# Submission time Handle Problem Language Result Execution time Memory
1016108 2024-07-07T11:53:38 Z JakobZorz Beech Tree (IOI23_beechtree) C++17
9 / 100
270 ms 179160 KB
#include"beechtree.h"
#include<algorithm>
#include<set>
#include<iostream>
#include<map>
#include<queue>
using namespace std;

int n;
vector<int>ch[200000];
map<int,int>ch_col[200000];
int par[200000];
int col[200000];
bool bad[200000];
int sub[200000];
bool res[200000];

void dfs1(int node){
    sub[node]=1;
    for(int c:ch[node]){
        dfs1(c);
        sub[node]+=sub[c];
    }
}

void dfs2(int node){
    bad[node]=ch[node].size()!=ch_col[node].size();
    for(int c:ch[node]){
        dfs2(c);
        bad[node]|=bad[c];
    }
}

bool good(int a,int b){
    for(auto[c,i]:ch_col[b])
        if(ch_col[a][c]<i)
            return false;
    return true;
}

// merge into s1
bool merge(set<pair<int,int>>&s1,set<pair<int,int>>&s2){
    bool res=true;
    for(auto i:s2){
        auto iter=s1.insert(i).first;
        auto iter2=iter,iter3=iter;
        if(iter3!=s1.begin()){
            iter3--;
            if(!good(iter->second,iter3->second))
                res=false;
        }
        
        iter2++;
        if(iter2!=s1.end()&&!good(iter2->second,iter->second))
            res=false;
    }
    return res;
}

set<pair<int,int>>get(int node){
    res[node]=!bad[node];
    set<pair<int,int>>s;
    s.insert({sub[node],node});
    for(int c:ch[node]){
        auto r=get(c);
        if(r.size()>s.size())
            swap(s,r);
        if(!merge(s,r))
            res[node]=false;
    }
    
    return s;
}

vector<int>beechtree(int N,int M,vector<int>P,vector<int>C){
    n=N;
    for(int i=0;i<n;i++)
        ch[i].clear();
    for(int i=0;i<n;i++){
        par[i]=P[i];
        if(i)
            ch[par[i]].push_back(i);
        col[i]=C[i];
    }
    dfs1(0);
    for(int i=0;i<n;i++){
        ch_col[i].clear();
        for(int c:ch[i])
            ch_col[i][col[c]]=sub[c];
    }
    dfs2(0);
    
    get(0);
    
    vector<int>res2(n);
    for(int i=0;i<n;i++)
        res2[i]=res[i];
    return res2;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14476 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Incorrect 9 ms 14380 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14476 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Incorrect 9 ms 14380 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14424 KB Output is correct
4 Correct 6 ms 14524 KB Output is correct
5 Correct 6 ms 14424 KB Output is correct
6 Correct 8 ms 14428 KB Output is correct
7 Correct 7 ms 14436 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14512 KB Output is correct
11 Correct 7 ms 14684 KB Output is correct
12 Correct 7 ms 14452 KB Output is correct
13 Correct 10 ms 14684 KB Output is correct
14 Correct 7 ms 14684 KB Output is correct
15 Correct 78 ms 27900 KB Output is correct
16 Correct 72 ms 26960 KB Output is correct
17 Correct 75 ms 27228 KB Output is correct
18 Correct 75 ms 27472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14424 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Incorrect 270 ms 179160 KB 2nd lines differ - on the 185766th token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14368 KB Output is correct
4 Correct 6 ms 14424 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 6 ms 14476 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Incorrect 9 ms 14380 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14424 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 5 ms 14428 KB Output is correct
7 Correct 5 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14424 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14424 KB Output is correct
12 Correct 8 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 7 ms 14320 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 14428 KB Output is correct
19 Correct 6 ms 14336 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 14428 KB Output is correct
23 Correct 6 ms 14428 KB Output is correct
24 Correct 6 ms 14428 KB Output is correct
25 Correct 7 ms 14936 KB Output is correct
26 Incorrect 6 ms 14940 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14368 KB Output is correct
4 Correct 6 ms 14424 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 6 ms 14476 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Incorrect 9 ms 14380 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14424 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 5 ms 14428 KB Output is correct
7 Correct 5 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14424 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14424 KB Output is correct
12 Correct 8 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 7 ms 14320 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 14428 KB Output is correct
19 Correct 6 ms 14336 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 14428 KB Output is correct
23 Correct 6 ms 14428 KB Output is correct
24 Correct 6 ms 14428 KB Output is correct
25 Correct 7 ms 14936 KB Output is correct
26 Incorrect 6 ms 14940 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14368 KB Output is correct
4 Correct 6 ms 14424 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 6 ms 14476 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Incorrect 9 ms 14380 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -