Submission #1067120

#TimeUsernameProblemLanguageResultExecution timeMemory
1067120ZanPBeech Tree (IOI23_beechtree)C++17
Compilation error
0 ms0 KiB
#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(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 (stderr)

beechtree.cpp: In function 'void dfs_subtree(int, std::vector<int>&)':
beechtree.cpp:16:11: error: found ':' in nested-name-specifier, expected '::'
   16 |     for(v : children[u]){
      |           ^
      |           ::
beechtree.cpp:16:9: error: 'v' has not been declared
   16 |     for(v : children[u]){
      |         ^
beechtree.cpp:19:1: error: expected primary-expression before '}' token
   19 | }
      | ^
beechtree.cpp:18:6: error: expected ';' before '}' token
   18 |     }
      |      ^
      |      ;
   19 | }
      | ~     
beechtree.cpp:19:1: error: expected primary-expression before '}' token
   19 | }
      | ^
beechtree.cpp:18:6: error: expected ')' before '}' token
   18 |     }
      |      ^
      |      )
   19 | }
      | ~     
beechtree.cpp:16:8: note: to match this '('
   16 |     for(v : children[u]){
      |        ^
beechtree.cpp:19:1: error: expected primary-expression before '}' token
   19 | }
      | ^
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