#include "beechtree.h"
#include <algorithm>
#include <map>
using namespace std;
const int N = 2e5 + 3;
int n, m, c[N], p[N];
vector<int> adj[N];
vector<int> get_subtree(int x){
vector<int> subtree{x};
for(int to: adj[x]){
vector<int> add = get_subtree(to);
for(int y: add){
subtree.push_back(y);
}
}
return subtree;
}
bool check(vector<int> &subtree){
map<int, int> cnt;
for(int i = 1; i < subtree.size(); ++i){
int node = subtree[i];
int color = c[node];
if(p[node] != subtree[cnt[color]]){
return false;
}
++cnt[color];
}
return true;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C)
{
n = N, m = M;
copy(C.begin(), C.end(), c);
copy(P.begin(), P.end(), p);
for(int i = 1; i < n; ++i){
adj[P[i]].push_back(i);
}
vector<int> ans;
for(int i = 0; i < n; ++i){
vector<int> subtree = get_subtree(i);
sort(subtree.begin(), subtree.end());
bool ok = false;
do{
if(subtree[0] != i){
continue;
}
if(check(subtree)){
ok = true;
break;
}
}
while(next_permutation(subtree.begin(), subtree.end()));
ans.push_back(ok);
}
return ans;
}
Compilation message
beechtree.cpp: In function 'bool check(std::vector<int>&)':
beechtree.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 1; i < subtree.size(); ++i){
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5468 KB |
Output is correct |
2 |
Execution timed out |
2083 ms |
5468 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5468 KB |
Output is correct |
2 |
Correct |
2 ms |
5468 KB |
Output is correct |
3 |
Correct |
1 ms |
5468 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
5468 KB |
Output is correct |
6 |
Correct |
2 ms |
5468 KB |
Output is correct |
7 |
Correct |
1 ms |
5468 KB |
Output is correct |
8 |
Correct |
1 ms |
5468 KB |
Output is correct |
9 |
Correct |
1 ms |
5468 KB |
Output is correct |
10 |
Correct |
1 ms |
5468 KB |
Output is correct |
11 |
Correct |
1 ms |
5468 KB |
Output is correct |
12 |
Correct |
1 ms |
5468 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 KB |
Output is correct |
14 |
Correct |
1 ms |
5468 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
1 ms |
5464 KB |
Output is correct |
17 |
Correct |
1 ms |
5468 KB |
Output is correct |
18 |
Correct |
1 ms |
5468 KB |
Output is correct |
19 |
Correct |
1 ms |
5468 KB |
Output is correct |
20 |
Correct |
1 ms |
5468 KB |
Output is correct |
21 |
Correct |
1 ms |
5468 KB |
Output is correct |
22 |
Correct |
2 ms |
5468 KB |
Output is correct |
23 |
Correct |
1 ms |
5468 KB |
Output is correct |
24 |
Correct |
1 ms |
5468 KB |
Output is correct |
25 |
Correct |
1 ms |
5468 KB |
Output is correct |
26 |
Correct |
1 ms |
5528 KB |
Output is correct |
27 |
Correct |
1 ms |
5468 KB |
Output is correct |
28 |
Correct |
1 ms |
5464 KB |
Output is correct |
29 |
Correct |
2 ms |
5468 KB |
Output is correct |
30 |
Correct |
1 ms |
5468 KB |
Output is correct |
31 |
Correct |
1 ms |
5468 KB |
Output is correct |
32 |
Correct |
2 ms |
5468 KB |
Output is correct |
33 |
Correct |
1 ms |
5468 KB |
Output is correct |
34 |
Correct |
1 ms |
5468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5468 KB |
Output is correct |
2 |
Correct |
2 ms |
5468 KB |
Output is correct |
3 |
Correct |
1 ms |
5468 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
5468 KB |
Output is correct |
6 |
Correct |
2 ms |
5468 KB |
Output is correct |
7 |
Execution timed out |
2058 ms |
47528 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2029 ms |
5464 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5468 KB |
Output is correct |
2 |
Correct |
2 ms |
5468 KB |
Output is correct |
3 |
Correct |
1 ms |
5468 KB |
Output is correct |
4 |
Correct |
1 ms |
5468 KB |
Output is correct |
5 |
Execution timed out |
2058 ms |
47528 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5468 KB |
Output is correct |
2 |
Execution timed out |
2083 ms |
5468 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5468 KB |
Output is correct |
2 |
Correct |
2 ms |
5468 KB |
Output is correct |
3 |
Correct |
1 ms |
5468 KB |
Output is correct |
4 |
Correct |
1 ms |
5468 KB |
Output is correct |
5 |
Correct |
1 ms |
5468 KB |
Output is correct |
6 |
Correct |
1 ms |
5468 KB |
Output is correct |
7 |
Correct |
1 ms |
5468 KB |
Output is correct |
8 |
Correct |
1 ms |
5468 KB |
Output is correct |
9 |
Correct |
1 ms |
5468 KB |
Output is correct |
10 |
Correct |
1 ms |
5468 KB |
Output is correct |
11 |
Correct |
2 ms |
5468 KB |
Output is correct |
12 |
Correct |
1 ms |
5464 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 KB |
Output is correct |
14 |
Correct |
1 ms |
5468 KB |
Output is correct |
15 |
Correct |
1 ms |
5468 KB |
Output is correct |
16 |
Correct |
1 ms |
5468 KB |
Output is correct |
17 |
Correct |
1 ms |
5468 KB |
Output is correct |
18 |
Correct |
2 ms |
5468 KB |
Output is correct |
19 |
Correct |
1 ms |
5468 KB |
Output is correct |
20 |
Correct |
1 ms |
5468 KB |
Output is correct |
21 |
Correct |
1 ms |
5468 KB |
Output is correct |
22 |
Correct |
1 ms |
5528 KB |
Output is correct |
23 |
Correct |
1 ms |
5468 KB |
Output is correct |
24 |
Correct |
1 ms |
5464 KB |
Output is correct |
25 |
Execution timed out |
2013 ms |
5936 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5468 KB |
Output is correct |
2 |
Execution timed out |
2083 ms |
5468 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5468 KB |
Output is correct |
2 |
Correct |
2 ms |
5468 KB |
Output is correct |
3 |
Correct |
1 ms |
5468 KB |
Output is correct |
4 |
Correct |
1 ms |
5468 KB |
Output is correct |
5 |
Correct |
1 ms |
5468 KB |
Output is correct |
6 |
Correct |
1 ms |
5468 KB |
Output is correct |
7 |
Correct |
1 ms |
5468 KB |
Output is correct |
8 |
Correct |
1 ms |
5468 KB |
Output is correct |
9 |
Correct |
1 ms |
5468 KB |
Output is correct |
10 |
Correct |
1 ms |
5468 KB |
Output is correct |
11 |
Correct |
2 ms |
5468 KB |
Output is correct |
12 |
Correct |
1 ms |
5464 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 KB |
Output is correct |
14 |
Correct |
1 ms |
5468 KB |
Output is correct |
15 |
Correct |
1 ms |
5468 KB |
Output is correct |
16 |
Correct |
1 ms |
5468 KB |
Output is correct |
17 |
Correct |
1 ms |
5468 KB |
Output is correct |
18 |
Correct |
2 ms |
5468 KB |
Output is correct |
19 |
Correct |
1 ms |
5468 KB |
Output is correct |
20 |
Correct |
1 ms |
5468 KB |
Output is correct |
21 |
Correct |
1 ms |
5468 KB |
Output is correct |
22 |
Correct |
1 ms |
5528 KB |
Output is correct |
23 |
Correct |
1 ms |
5468 KB |
Output is correct |
24 |
Correct |
1 ms |
5464 KB |
Output is correct |
25 |
Execution timed out |
2013 ms |
5936 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5468 KB |
Output is correct |
2 |
Execution timed out |
2083 ms |
5468 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |