Submission #1066978

#TimeUsernameProblemLanguageResultExecution timeMemory
1066978pccBeech Tree (IOI23_beechtree)C++17
0 / 100
17 ms30704 KiB
#include "beechtree.h" #include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second const int mxn = 2e5+10; pii par[mxn]; vector<pii> tree[mxn]; vector<int> col[mxn]; vector<int> sub[mxn]; vector<int> ans; int cnt[mxn]; void dfs(int now){ memset(cnt,0,sizeof(cnt)); sub[now].push_back(now); for(auto [nxt,w]:tree[now]){ dfs(nxt); for(auto &i:sub[nxt])sub[now].push_back(i); } vector<int> v = sub[now]; sort(v.begin()+1,v.end()); if(v.size() == 1)ans[now] = 1; else ans[now] = 0; do{ bool flag = true; for(int i = 1;i<v.size();i++){ int tmp = v[i]; auto [p,w] = par[tmp]; int num = cnt[w]; if(v[num] != p)flag = false; cnt[w]++; } if(flag)ans[now] = 1; }while(next_permutation(v.begin()+1,v.end())); return; } std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){ ans = vector<int>(N,1); for(int i = 1;i<N;i++){ int p = P[i]; tree[p].push_back(pii(i,C[i])); par[i] = pii(p,C[i]); col[C[i]].push_back(p); } dfs(0); return ans; }

Compilation message (stderr)

beechtree.cpp: In function 'void dfs(int)':
beechtree.cpp:33:18: 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++){
      |                 ~^~~~~~~~~
#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...