답안 #1071071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071071 2024-08-23T04:08:08 Z Muhammad_Aneeq 참나무 (IOI23_beechtree) C++17
0 / 100
1 ms 7516 KB
#include <vector>
#include <algorithm>
#include <set>
#include <iostream>
using namespace std;
int const MAXN=2e5+10;
vector<int>nei[MAXN]={};
int c[MAXN]={};
int h[MAXN]={};
int ans[MAXN]={};
int ind[MAXN]={};
int cnt[MAXN]={};
int p[MAXN]={};
bool check(vector<int>d,int u)
{
	for (auto i:d)
		ind[i]=-1,cnt[c[i]]=0;
	int z=1;
	for (auto i:d)
	{
		if (ind[p[i]]==-1)
			return 0;
		if (cnt[c[i]]!=ind[p[i]])
			return 0;
		ind[i]=z++;
		cnt[c[i]]++;
	}
	return 1;
}
vector<int> dfs(int u)
{
	vector<int>d;
	for (auto i:nei[u])
	{
		h[i]=h[u]+1;
		vector<int>f=dfs(i);
		for (auto i:f)
			d.push_back(i);
	}
	sort(begin(d),end(d));
	while (!check(d,u))
	{
		if (!next_permutation(begin(d),end(d)))
		{
			ans[u]=0;
			break;
		}
	}
	return d;
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C)
{
	for (int i=0;i<N;i++)
		c[i]=C[i],p[i]=P[i],ans[i]=1;
	for (int i=1;i<N;i++)
		nei[P[i]].push_back(i);
	dfs(0);
	vector<int>d;
	for (int i=0;i<N;i++)
		d.push_back(ans[i]);
	return d;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7512 KB Output is correct
2 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7512 KB Output is correct
2 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7512 KB Output is correct
2 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7512 KB Output is correct
2 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7512 KB Output is correct
2 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 7516 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -