제출 #1129740

#제출 시각아이디문제언어결과실행 시간메모리
1129740MMihalev참나무 (IOI23_beechtree)C++17
0 / 100
2095 ms17476 KiB
#include "beechtree.h" #include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; const int MAX_N=2e5+5; int n,m; vector<pair<int,int>>g[MAX_N]; int par[MAX_N]; int col[MAX_N]; bool cmp(pair<int,int> i1,pair<int,int> i2) { int s1=g[i1.first].size(); int s2=g[i2.first].size(); return s1>s2; } int seq[MAX_N]; int cnt[MAX_N]; int sz; bool check(int u) { if(sz>0) { if(seq[cnt[col[u]]]!=par[u])return 0; cnt[col[u]]++; } seq[sz++]=u; return 1; } bool solve(int r) { sz=0; for(int i=1;i<=m;i++)cnt[i]=0; vector<int>q; q.push_back(r); while(q.size()) { vector<int>nq; int Szq=q.size(); int pos=0; while(Szq>0) { int u=q[pos]; pos++; Szq--; if(check(u)==0)return 0; for(auto [v,edge]:g[u]) { nq.push_back(v); } } swap(q,nq); } return 1; } std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C) { n=N; m=M; vector<int>ans; ans.resize(n); for(int i=1;i<n;i++) { par[i]=P[i]; col[i]=C[i]; g[P[i]].push_back({i,C[i]}); } for(int i=0;i<n;i++) { sort(g[i].begin(),g[i].end(),cmp); } for(int i=0;i<n;i++) { ans[i]=solve(i); } 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...