답안 #1016079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016079 2024-07-07T11:28:45 Z JakobZorz 참나무 (IOI23_beechtree) C++17
컴파일 오류
0 ms 0 KB
#include"beechtree.h"
#include<algorithm>
#include<set>
#include<iostream>
#include<map>
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];

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 get(int node){
    if(bad[node])
        return false;
    
    int cs=node;
    priority_queue<pair<int,int>>q;
    for(int c:ch[node])
        q.push({ch[c].size(),c});
    
    while(q.size()){
        int cn=q.top().second;
        q.pop();
        for(auto[c,i]:ch_col[cn])
            if(ch_col[cs][c]<i)
                return false;
        cs=cn;
        for(int c:ch[cn])
            q.push({ch[c].size(),c});
    }
    
    return true;
}

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);
    vector<int>res(n);
    for(int i=0;i<n;i++)
        res[i]=get(i);
    return res;
}

Compilation message

beechtree.cpp: In function 'bool get(int)':
beechtree.cpp:37:5: error: 'priority_queue' was not declared in this scope
   37 |     priority_queue<pair<int,int>>q;
      |     ^~~~~~~~~~~~~~
beechtree.cpp:6:1: note: 'std::priority_queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
    5 | #include<map>
  +++ |+#include <queue>
    6 | using namespace std;
beechtree.cpp:37:32: error: expected primary-expression before '>' token
   37 |     priority_queue<pair<int,int>>q;
      |                                ^~
beechtree.cpp:37:34: error: 'q' was not declared in this scope
   37 |     priority_queue<pair<int,int>>q;
      |                                  ^