Submission #980977

#TimeUsernameProblemLanguageResultExecution timeMemory
980977FZ_MeloBeech Tree (IOI23_beechtree)C++17
0 / 100
2079 ms28496 KiB
#include "beechtree.h" #include <bits/stdc++.h> using namespace std; struct ari{ int node, c; }; int n, m, maxlevel=0; int buc[200000]; bool used[200000]; bool ya=0; ari papa[200000]; vector<vector<ari>> adj; vector<int> perm, nums; void busca(int node){ nums.push_back(node); for(auto h: adj[node]){ busca(h.node); } } void nextperm(int pos){ if(ya) return; if(pos==nums.size()){ for(int i=1; i<perm.size(); i++){ if(perm[buc[papa[perm[i]].c]]!=papa[perm[i]].node) return; buc[papa[perm[i]].c]++; } ya=1; return; } for(int i=0; i<nums.size() && ya==0; i++){ if(used[nums[i]]) continue; used[nums[i]]=1; perm[pos]=nums[i]; nextperm(pos+1); used[nums[i]]=0; if(pos==0) return; } } bool checa(int node){ busca(node); perm.clear(); perm.resize(nums.size()); nextperm(0); return ya; } std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){ n=N, m=M; adj.resize(n); for(int i=1; i<n; i++){ adj[P[i]].push_back({i, C[i]}); papa[i]={P[i], C[i]}; } vector<int> ans(n); for(int i=0; i<n; i++){ nums.clear(); ya=0; if(checa(i)) ans[i]=1; for(int j=0; j<=m; j++) buc[j]=0; for(int j=0; j<n; j++) used[j]=0; } return ans; }

Compilation message (stderr)

beechtree.cpp: In function 'void nextperm(int)':
beechtree.cpp:28:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(pos==nums.size()){
      |        ~~~^~~~~~~~~~~~~
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<perm.size(); i++){
      |                      ~^~~~~~~~~~~~
beechtree.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=0; i<nums.size() && ya==0; i++){
      |                  ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...