Submission #1074749

#TimeUsernameProblemLanguageResultExecution timeMemory
1074749UnforgettableplBeech Tree (IOI23_beechtree)C++17
26 / 100
2095 ms19532 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); auto check = [&](int root){ map<int,int> cnt; priority_queue<tuple<int,int,int>> q; vector seq = {root}; for(int&i:adj[root])q.emplace(adj[i].size(),0,i); while(!q.empty()) { auto [a,b,curr] = q.top();q.pop(); if(seq[cnt[C[curr]]]!=P[curr])return false; cnt[C[curr]]++; seq.emplace_back(curr); for(int&i:adj[curr])q.emplace(adj[i].size(),-(seq.size()-1),i); } return true; }; for(int i=0;i<N;i++)if(check(i))ans[i]=1; 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...