# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1024746 | LIF | 참나무 (IOI23_beechtree) | C++17 | 97 ms | 43580 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "beechtree.h"
#include<bits/stdc++.h>
#include<vector>
#include<map>
using namespace std;
vector<int> vv[500005];
int maxdepth[500005];
int depth[500005];
int ans[500005];
void dfs(int now,int dep)
{
maxdepth[now] = depth[now] = dep;
for(auto it : vv[now])
{
dfs(it,dep+1);
maxdepth[now] = max(maxdepth[now],maxdepth[it]);
}
return;
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C)
{
for(int i=1;i<P.size();i++)
{
int father = P[i];
int son = i;
vv[father].push_back(son);
}
dfs(0,1);
// ???憭???暺?
for(int i=0;i<N;i++)
{
if(maxdepth[i] == depth[i])ans[i] = 1;
else
{
if(maxdepth[i] == depth[i] + 1)
{
map<int,int> mp;
bool flag = true;
for(auto it : vv[i])
{
int nowcolor = C[it];
if(mp[nowcolor] != 0)
{
flag = false;
break;
}
else mp[nowcolor] = 1;
}
if(flag == true)ans[i] = 1;
else ans[i] = 0;
}
else
{
if(maxdepth[i] == depth[i] + 2)
{
map<int,int> mp;
bool flag = true;
for(auto it : vv[i]) //擐?靽??????脤???詨?嚗?
{
int nowcolor = C[it];
if(mp[nowcolor] != 0)
{
flag = false;
break;
}
else mp[nowcolor] = 1;
}
int cnt = 0;
for(auto it : vv[i])
{
if(vv[it].size() >= 1)
{
cnt++;
map<int,int> mp2;
for(auto j : vv[it])
{
int nowcolor = C[j];
if(mp2[nowcolor] != 0)
{
flag = false;
break;
}
else mp2[nowcolor] = 1;
if(mp[nowcolor] == 0)flag = false;
}
}
}
if(cnt >= 2)flag = false;
if(flag == true)ans[i] = 1;
else ans[i] = 0;
}
else ans[i] = 0;
}
}
}
vector<int> temp;
for(int i=0;i<N;i++)
{
temp.push_back(ans[i]);
}
/* for(int i=0;i<100;i++)if(ans[i] == 0)cout<<i<<endl;
cout<<maxdepth[49]<<" "<<depth[49]<<" "<<ans[49]<<endl;
for(auto it : vv[49])
{
cout<<it<<" "<<vv[it].size()<<" "<<C[it]<<" "<<endl;
cout<<"son"<<endl;
if(vv[it].size() == 2)cout<<vv[it][0]<<" "<<C[vv[it][0]]<<endl;
if(vv[it].size() == 2)cout<<vv[it][1]<<" "<<C[vv[it][1]]<<endl;
cout<<endl;
}
*/
return temp;
}
컴파일 시 표준 에러 (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... |