답안 #1067121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067121 2024-08-20T11:40:42 Z ZanP 참나무 (IOI23_beechtree) C++17
컴파일 오류
0 ms 0 KB
#include "beechtree.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define ll long long

int n, m;
vector<int> parents, colors;
vector<vector<int>> children;

void dfs_subtree(int u, vector<int> & subtree)
{
    subtree.push_back(u);
    for(int v : children[u]){
        dfs_subtree(v);
    }
}

vector<int> get_subtree(int u)
{
    vector<int> subtree;
    subtree.reserve(n);
    dfs_subtree(u, subtree);
    return subtree;
}

bool check_permutation(int u, vector<int> & v){
    if(v[0] != u) return false;
    unordered_map<int, int> f;
    f.resize(M);
    for (int i = 1; i < v.size(); i++)
    {
        if(!f[colors[i]].count()) f[colors[i]] = 0;
        if(parent[[v[i]]] != v[f[colors[i]]]) return false;
        f[colors[i]]++;
    }
    return true;
}

vector<int> beechtree(int N, int M, vector<int> P, vector<int> C){
    n = N; m = M; parents = P; colors = C;  
    children.resize(N);
    vector<int> ans;
    ans.resize(N,0);
    for(int child = 1; child < N; child++)
    {
        children[P[child]].push_back(child);
    }

    // brute force
    for(int u = 0; u<n; u++)
    {
        subtree = get_subtree(u);
        sort(subtree.begin(), subtree.end());
        if(check_permutation(subtree)){
            ans[u] = 1;
            continue;
        }
        while(next_permutation(subtree.begin(), subtree.end())){
            if(check_permutation(u, subtree)){
            ans[u] = 1;
            break;
            }
        }
    }

    return ans;
}


Compilation message

beechtree.cpp: In function 'void dfs_subtree(int, std::vector<int>&)':
beechtree.cpp:17:22: error: too few arguments to function 'void dfs_subtree(int, std::vector<int>&)'
   17 |         dfs_subtree(v);
      |                      ^
beechtree.cpp:13:6: note: declared here
   13 | void dfs_subtree(int u, vector<int> & subtree)
      |      ^~~~~~~~~~~
beechtree.cpp: In function 'bool check_permutation(int, std::vector<int>&)':
beechtree.cpp:32:7: error: 'class std::unordered_map<int, int>' has no member named 'resize'; did you mean 'size'?
   32 |     f.resize(M);
      |       ^~~~~~
      |       size
beechtree.cpp:32:14: error: 'M' was not declared in this scope
   32 |     f.resize(M);
      |              ^
beechtree.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = 1; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
beechtree.cpp:35:26: error: request for member 'count' in 'f.std::unordered_map<int, int>::operator[]((*(const key_type*)(& colors.std::vector<int>::operator[](((std::vector<int>::size_type)i)))))', which is of non-class type 'std::unordered_map<int, int>::mapped_type' {aka 'int'}
   35 |         if(!f[colors[i]].count()) f[colors[i]] = 0;
      |                          ^~~~~
beechtree.cpp:36:12: error: 'parent' was not declared in this scope; did you mean 'parents'?
   36 |         if(parent[[v[i]]] != v[f[colors[i]]]) return false;
      |            ^~~~~~
      |            parents
beechtree.cpp:36:18: error: two consecutive '[' shall only introduce an attribute before '[' token
   36 |         if(parent[[v[i]]] != v[f[colors[i]]]) return false;
      |                  ^
beechtree.cpp:36:18: error: expected ')' before '[' token
   36 |         if(parent[[v[i]]] != v[f[colors[i]]]) return false;
      |           ~      ^
      |                  )
beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:55:9: error: 'subtree' was not declared in this scope; did you mean 'get_subtree'?
   55 |         subtree = get_subtree(u);
      |         ^~~~~~~
      |         get_subtree