Submission #1344088

#TimeUsernameProblemLanguageResultExecution timeMemory
1344088phamngocphuc2008September (APIO24_september)C++20
0 / 100
1 ms344 KiB
#include "september.h"

#include <bits/stdc++.h>
using namespace std;

int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
	auto check = [&](const vector<int>& seq)
	{
		vector<bool> used(N);
		used[0] = true;
		for(int i = N-2; i >=0; --i)
		{
			int leaf = seq[i];
			int par = F[leaf];
			if(!used[par]) return false;
			used[leaf] = true;
		}
		return true;
	};
	for(const auto &seq : S) if(!check(seq)) return -1;
	vector<int> cnt(N);
	int k = 0;
	for(int i = 0; i + 1 < N; ++i)
	{
		for(int j = 0; j < M; ++j) 
		{
			int leaf = S[j][i];
			cnt[leaf]++;
		}
		bool ok = true;
		for(int j = 0; j < N; ++j)
		{
			if(cnt[j] != 0 && cnt[j] != M) 
			{
				ok = false;
				break;
			}
		}
		if(ok) ++k; 
	}
	return k;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...