Submission #857557

# Submission time Handle Problem Language Result Execution time Memory
857557 2023-10-06T11:55:44 Z mychecksedad Beech Tree (IOI23_beechtree) C++17
14 / 100
100 ms 75784 KB
#include <beechtree.h>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 2e5+100;

int sz[N], dep[N], par[N], n, max_dep[N];
vector<array<int, 2>> g[N];
vector<array<int, 3>> s[N];
vector<int> ans, COL, is_full;
set<int> C[N];

void dfs(int v){
	ans[v] = 1;
	sz[v] = 1;
	max_dep[v] = dep[v];
	for(auto U: g[v]){
		int u = U[0], c = U[1];

		dep[u] = dep[v] + 1;
		par[u] = v;
		dfs(u);
		max_dep[v] = max(max_dep[v], max_dep[u]);

		sz[v] += sz[u];
		ans[v] &= ans[u];

		if(C[v].find(c) != C[v].end()) ans[v] = 0;
		C[v].insert(c);
	}
	if(ans[v] == 0) return;

	sort(all(g[v]), [&](const array<int, 2> &x, const array<int, 2> &y){
		return sz[x[0]] > sz[y[0]];
	});

	for(int i = 0; i < g[v].size(); ++i){
		int x = (i == 0 ? v : g[v][i - 1][0]), y = g[v][i][0];
		for(auto col: C[y]){
			if(C[x].find(col) == C[x].end()){
				ans[v] = 0;
				break;
			}
		}
	}

	if(ans[v] == 0) return;	

	if(g[v].size() == 0){
		is_full[v] = 1;
	}else if(g[v].size() == 1){
		is_full[v] = 0;
	}else{
		if(!is_full[g[v][0][0]]){
			ans[v] = 0;
		}
		ans[v] &= abs(max_dep[g[v][0][0]] - max_dep[g[v][1][0]]) <= 1;
		is_full[v] = (is_full[g[v][0][0]] & is_full[g[v][1][0]]);
	}
}

vector<int> beechtree(int nn, int m, vector<int> P, vector<int> CC){
	COL = CC;
	n = nn;
	for(int i = 1; i < n; ++i){
		g[P[i]].pb({i, COL[i]});
	}
	ans.resize(n);
	is_full.resize(n);

	dep[0] = 0;
	dfs(0);

	return ans;
}	

Compilation message

beechtree.cpp: In function 'void dfs(int)':
beechtree.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i = 0; i < g[v].size(); ++i){
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Incorrect 5 ms 21084 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21336 KB Output is correct
5 Correct 4 ms 21084 KB Output is correct
6 Correct 4 ms 21084 KB Output is correct
7 Correct 4 ms 21080 KB Output is correct
8 Correct 4 ms 21084 KB Output is correct
9 Correct 4 ms 21084 KB Output is correct
10 Incorrect 4 ms 21084 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21336 KB Output is correct
5 Correct 4 ms 21084 KB Output is correct
6 Correct 4 ms 21084 KB Output is correct
7 Correct 93 ms 75348 KB Output is correct
8 Correct 93 ms 75688 KB Output is correct
9 Correct 4 ms 21080 KB Output is correct
10 Correct 4 ms 21080 KB Output is correct
11 Correct 5 ms 21108 KB Output is correct
12 Correct 4 ms 21084 KB Output is correct
13 Correct 5 ms 21444 KB Output is correct
14 Correct 5 ms 21596 KB Output is correct
15 Correct 5 ms 21596 KB Output is correct
16 Correct 5 ms 21596 KB Output is correct
17 Correct 95 ms 75440 KB Output is correct
18 Correct 94 ms 75348 KB Output is correct
19 Correct 100 ms 75784 KB Output is correct
20 Correct 95 ms 75592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 4 ms 21084 KB Output is correct
6 Correct 4 ms 21084 KB Output is correct
7 Correct 5 ms 21336 KB Output is correct
8 Correct 4 ms 21084 KB Output is correct
9 Correct 4 ms 21084 KB Output is correct
10 Correct 5 ms 21340 KB Output is correct
11 Correct 5 ms 21080 KB Output is correct
12 Correct 4 ms 21084 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 21084 KB Output is correct
15 Correct 62 ms 30748 KB Output is correct
16 Correct 60 ms 30288 KB Output is correct
17 Correct 53 ms 30544 KB Output is correct
18 Correct 54 ms 30548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 4 ms 21080 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 93 ms 75348 KB Output is correct
6 Correct 93 ms 75688 KB Output is correct
7 Incorrect 4 ms 21084 KB 2nd lines differ - on the 156th token, expected: '1', found: '0'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Incorrect 5 ms 21084 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 4 ms 21080 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 4 ms 21084 KB Output is correct
6 Incorrect 4 ms 21084 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Incorrect 5 ms 21084 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 4 ms 21080 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 4 ms 21084 KB Output is correct
6 Incorrect 4 ms 21084 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Incorrect 5 ms 21084 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -