Submission #980925

# Submission time Handle Problem Language Result Execution time Memory
980925 2024-05-12T15:49:55 Z vjudge1 Beech Tree (IOI23_beechtree) C++17
9 / 100
47 ms 16080 KB
#include "beechtree.h"
using namespace std;
#define pb push_back
#include<bits/stdc++.h>
#define deb(x) cout<<#x<<": "<<x<<endl;
bool DFS (int N, vector<vector<int>> &sons,vector<int> &P, vector<int> &C){
    if(sons[N].size()==0) return true;
    vector<int> st;
    st.pb(N);
    queue<int> q;
    for(int x: sons[N]){
        q.push(x);
    }
    while(!q.empty()){
        int x=q.front();
        q.pop();
        st.pb(x);
        for(int a:sons[x]){
            q.push(a);
        }
    }

    sort(st.begin(), st.end());
    do{
   
        vector<int> colors;
        //colors.pb(C[st[0]]);
        bool works=true;
        for(int i=1; i<st.size(); ++i){ 
            int cont=0;
            for(int x: colors){
                if(x==C[st[i]]){
                    cont++;
                }
            }
            if(st[cont]!=P[st[i]]){
                works=false;
                break;
            }
            colors.pb(C[st[i]]);
        }
        if(works){
            return true;
        }
    }while(next_permutation(st.begin()+1, st.end()));
    return false;

}

vector<int> beechtree(int N, int M, vector<int> P, vector<int> C)
{
    vector<vector<int>> sons (N);
    for(int i=1;i<N; ++i){
        sons[P[i]].pb(i);
    }
    if(N<=8){
    vector<int> ans (N,0);
    
    for(int i=0; i<N; ++i){
        if(DFS(i, sons, P, C)){
            ans[i]=1;
        }
    }
    return ans;
    }

    vector<int> ord;
    ord.pb(0);
    while(sons[ord[ord.size()-1]].size()!=0){
        ord.pb(sons[ord[ord.size()-1]][0]);
    }
    vector<int> ans (N, 0);
    reverse(ord.begin(), ord.end());
    ans[ord[0]]=1;
    int color=C[ord[0]];
    for(int i=0; i<ord.size(); ++i){
        if(C[ord[0]]==color){
            ans[ord[i+1]]=1;
        }
        else{
            return ans;
        }
    }



    return {};
}

Compilation message

beechtree.cpp: In function 'bool DFS(int, std::vector<std::vector<int> >&, std::vector<int>&, std::vector<int>&)':
beechtree.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int i=1; i<st.size(); ++i){
      |                      ~^~~~~~~~~~
beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:76:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i=0; i<ord.size(); ++i){
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 2nd lines differ - expected: 18 tokens, found 0 tokens
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 500 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 360 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Incorrect 47 ms 16080 KB 2nd lines differ - expected: 200000 tokens, found 0 tokens
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 2nd lines differ - expected: 115 tokens, found 0 tokens
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 500 KB Output is correct
5 Incorrect 47 ms 16080 KB 2nd lines differ - expected: 200000 tokens, found 0 tokens
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 2nd lines differ - expected: 18 tokens, found 0 tokens
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 500 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Incorrect 1 ms 348 KB 2nd lines differ - expected: 2000 tokens, found 0 tokens
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 2nd lines differ - expected: 18 tokens, found 0 tokens
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 500 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Incorrect 1 ms 348 KB 2nd lines differ - expected: 2000 tokens, found 0 tokens
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 2nd lines differ - expected: 18 tokens, found 0 tokens
3 Halted 0 ms 0 KB -