Submission #995449

# Submission time Handle Problem Language Result Execution time Memory
995449 2024-06-09T06:10:08 Z irmuun Beech Tree (IOI23_beechtree) C++17
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>
#include "beechtree.h"

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define pii pair<int,int>

vector<int>beechtree(int n,int m,vector<int>p,vector<int>c){
    vector<int>g[n],col[n];
    for(int i=1;i<n;i++){
        g[p[i]].pb(i);
        col[p[i]].pb(c[i]);
    }
    vector<bool>same(n,false);
    for(int i=0;i<n;i++){
        sort(all(col[i]));
        for(int j=1;j<col[i].size();j++){
            if(col[i][j]==col[i][j-1]){
                same[j]=true;
            }
        }
    }
    vector<int>b(n,0),f(m+1,0);
    for(int i=0;i<n;i++){
        vector<int>u;
        priority_queue<pii,vector<pii>,greater<pii>>q;
        q.push({g[i].size(),i});
        bool ok=true;
        while(!q.empty()){
            auto [sz,x]=q.top();
            u.pb(x);
            if(same[x]){
                ok=false;
            }
            q.pop();
            for(int y:g[x]){
                q.push({g[y].size(),y});
            }
        }
        if(!ok){
            continue;
        }
        for(int j=1;j<u.size();j++){
            if(g[u[j]].size()>g[u[j-1]].size()){
                ok=false;
                break;
            }
            int pos=0;
            for(int k=0;k<g[u[j]].size();k++){
                while(pos<g[u[j-1]].size()&&g[u[j-1]][pos]!=g[u[j]][k]){
                    pos++;
                }
                if(pos==g[u[j-1]].size()){
                    ok=false;
                    break;
                }
                pos++;
            }
            if(!ok){
                break;
            }
        }
        if(ok){
            b[i]=1;
        }
    }
    return b;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for(int j=1;j<col[i].size();j++){
      |                     ~^~~~~~~~~~~~~~
beechtree.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int j=1;j<u.size();j++){
      |                     ~^~~~~~~~~
beechtree.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for(int k=0;k<g[u[j]].size();k++){
      |                         ~^~~~~~~~~~~~~~~
beechtree.cpp:56:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |                 while(pos<g[u[j-1]].size()&&g[u[j-1]][pos]!=g[u[j]][k]){
      |                       ~~~^~~~~~~~~~~~~~~~~
beechtree.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |                 if(pos==g[u[j-1]].size()){
      |                    ~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 2nd lines differ - on the 15th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -