Submission #1074766

#TimeUsernameProblemLanguageResultExecution timeMemory
1074766UnforgettableplBeech Tree (IOI23_beechtree)C++17
0 / 100
56 ms33092 KiB
#include "beechtree.h" #include <bits/stdc++.h> using namespace std; vector<int> beechtree(int N,int M,vector<int> P,vector<int> C){ vector<int> ans(N); vector<vector<int>> adj(N); for(int i=1;i<N;i++)adj[P[i]].emplace_back(i); function<int(int)> dfs = [&](int x){ vector<bool> contains(3); int state = -1; bool works = true; for(int&i:adj[x]) { if(contains[C[i]]) { works=false; } contains[C[i]]=true; auto curr = dfs(i); if(curr==-2) { works = false; continue; } if(curr==-1)continue; if(state!=-1 and state!=curr) { works=false; continue; } state=curr; } if(contains[1] and !contains[2]) { if(state==2)return -2; state=1; } if(!contains[1] and contains[2]) { if(state==1)return -2; state=2; } if(!works)return -2; ans[x]=1; return state; }; dfs(0); return ans; }
#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...