# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1061289 | tolbi | 참나무 (IOI23_beechtree) | C++17 | 1 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
bool valid(vector<vector<int>> &arr){
vector<int> in(arr.size());
for (int i = 0; i < arr.size(); i++){
for (auto it : arr[i]){
in[it]++;
}
}
queue<int> q;
int say = 0;
for (int i = 0; i < arr.size(); i++){
if (in[i]==0) q.push(i);
}
while (q.size()){
int node = q.front();
say++;
q.pop();
for (auto it : arr[node]){
in[it]--;
if (in[it]==0) q.push(it);
}
}
return (say==arr.size());
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C)
{
vector<int> ans(N);
vector<vector<int>> arr(N);
for (int i = 1; i < N; i++){
arr[P[i]].push_back(i);
}
cout<<arr[1].size()<<endl;
vector<set<int>> v(N);
function<void(int)> dfs = [&](int node)->void{
bool boolean=true;
map<int,vector<int>> mp;
map<int,int> vv;
int ind = 0;
for (auto it : arr[node]){
dfs(it);
if (ans[it]==0){
boolean=false;
}
if (boolean){
for (auto it2 : v[it]){
mp[it2].push_back(ind);
}
vv[C[it]]=ind;
ind++;
}
}
if (vv.size()!=arr[node].size()){
boolean=false;
}
if (boolean){
vector<vector<int>> gr(arr[node].size());
for (auto it : mp){
int hh = vv[it.first];
for (auto it2 : it.second){
if (hh==it2) continue;
gr[hh].push_back(it2);
}
}
if (!valid(gr)){
boolean=false;
}
}
if (boolean){
for (auto it : mp){
v[node].insert(it.first);
}
for (auto it : arr[node]){
v[node].insert(C[it]);
}
if (v[node].size()!=arr[node].size()){
boolean=false;
while (v[node].size()) v[node].erase(v[node].begin());
return;
}
ans[node]=1;
}
};
dfs(0);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |