Submission #1074780

#TimeUsernameProblemLanguageResultExecution timeMemory
1074780UnforgettableplBeech Tree (IOI23_beechtree)C++17
0 / 100
50 ms33188 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<pair<int,int>(int)> dfs = [&](int x)->pair<int,int>{ vector<bool> contains(3); int state = -1; bool works = true; int maxsize = 0; for(int&i:adj[x]) { if(contains[C[i]]) { works=false; } contains[C[i]]=true; auto [curr,st] = dfs(i); maxsize=max(st,maxsize); 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,max(maxsize,(int)adj[x].size())}; state=1; } if(!contains[1] and contains[2]) { if(state==1)return {-2,max(maxsize,(int)adj[x].size())}; state=2; } if(maxsize>adj[x].size())works=false; if(!works)return {-2,max(maxsize,(int)adj[x].size())}; ans[x]=1; return {state,max(maxsize,(int)adj[x].size())}; }; dfs(0); return ans; }

Compilation message (stderr)

beechtree.cpp: In lambda function:
beechtree.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if(maxsize>adj[x].size())works=false;
      |            ~~~~~~~^~~~~~~~~~~~~~
#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...