Submission #1066983

# Submission time Handle Problem Language Result Execution time Memory
1066983 2024-08-20T09:15:26 Z pcc Beech Tree (IOI23_beechtree) C++17
0 / 100
18 ms 30556 KB
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define fs first
#define sc second

const int mxn = 2e5+10;

pii par[mxn];
vector<pii> tree[mxn];
vector<int> col[mxn];
vector<int> sub[mxn];
vector<int> ans;
int cnt[mxn];

void dfs(int now){
	memset(cnt,0,sizeof(cnt));
	sub[now].push_back(now);
	for(auto [nxt,w]:tree[now]){
		dfs(nxt);
		for(auto &i:sub[nxt])sub[now].push_back(i);
	}
	vector<int> v = sub[now];
	if(v.size() == 1){
		ans[now] = 1;
		return;
	}
	sort(v.begin()+1,v.end());
	ans[now] = 0;


	do{
		bool flag = true;
		for(int i = 1;i<v.size();i++){
			int tmp = v[i];
			auto [p,w] = par[tmp];
			int num = cnt[w];
			if(v[num] != p)flag = false;
			cnt[w]++;
		}
		if(flag)ans[now] = 1;
	}while(next_permutation(v.begin()+1,v.end()));
	return;
}


std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){
	ans = vector<int>(N,1);
	for(int i = 1;i<N;i++){
		int p = P[i];
		tree[p].push_back(pii(i,C[i]));
		par[i] = pii(p,C[i]);
		col[C[i]].push_back(p);
	}
	dfs(0);
	return ans;
}

Compilation message

beechtree.cpp: In function 'void dfs(int)':
beechtree.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for(int i = 1;i<v.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15192 KB Output is correct
2 Runtime error 18 ms 30516 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 15196 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 15196 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 30556 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 15196 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15192 KB Output is correct
2 Runtime error 18 ms 30516 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 15196 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15192 KB Output is correct
2 Runtime error 18 ms 30516 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 15196 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15192 KB Output is correct
2 Runtime error 18 ms 30516 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -