Submission #1072904

#TimeUsernameProblemLanguageResultExecution timeMemory
1072904MuhammadSaramBeech Tree (IOI23_beechtree)C++17
5 / 100
57 ms6740 KiB
#include <bits/stdc++.h> using namespace std; const int M = 2000; vector<int> nei[M]; int col[M],par[M],s[M],t; bool pos[M]; void dfs(int u) { s[u]=++t; for (int i:nei[u]) dfs(i); vector<int> v; for (int i=0;i<M;i++) if (!s[i]) break; else if(s[i]>=s[u]) v.push_back(i); sort(v.begin(),v.end()); do { if (v[0]!=u) continue; map<int,int> cnt; bool b=1; for (int j=1;j<v.size() && b;j++) { int i=v[j]; if (v[cnt[col[i]]]!=par[i]) b=0; else cnt[col[i]]++; } if (b) { pos[u]=1; break; } }while(next_permutation(v.begin(),v.end())); } vector<int> beechtree(int n, int m, vector<int> p, vector<int> c) { vector<int> ans(n); if (n<=8) { for (int i=0;i<n;i++) col[i]=c[i],par[i]=p[i]; for (int i=1;i<n;i++) nei[p[i]].push_back(i); dfs(0); for (int i=0;i<n;i++) ans[i]=pos[i]; return ans; } set<int> se; for (int i=n-1;i>=0;i--) { ans[i]=1; se.insert(c[i]); if (se.size()==2) break; } return ans; }

Compilation message (stderr)

beechtree.cpp: In function 'void dfs(int)':
beechtree.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int j=1;j<v.size() && b;j++)
      |                ~^~~~~~~~~
#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...