#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];
vector<array<int, 2>> g[N], s[N];
vector<int> ans, COL;
set<int> C[N];
void dfs(int v){
ans[v] = 1;
sz[v] = 1;
s[v].pb({v, COL[v]});
for(auto U: g[v]){
int u = U[0], c = U[1];
dep[u] = dep[v] + 1;
par[u] = v;
dfs(u);
for(auto x: s[u]) s[v].pb(x);
sz[v] += sz[u];
// ans[v] &= ans[u];
// if(C[v].find(c) != C[v].end()) ans[v] = 0;
// C[v].insert(c);
}
sort(s[v].begin() + 1, s[v].end());
ans[v] = 0;
do{
bool ok = 1;
map<int, int> colptr;
for(int i = 1; i < s[v].size(); ++i){
int u = s[v][i][0], co = s[v][i][1];
if(par[u] != s[v][colptr[co]][0]){
ok = 0;
break;
}
colptr[co]++;
}
if(ok){
ans[v] = 1;
break;
}
}while(next_permutation(s[v].begin() + 1, s[v].end()));
// 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(g[v].size() > 1){
// if(abs(dep[g[v][0][0]] - dep[g[v][1][0]]) > 1) ans[v] = 0;
// }
// if(ans[v] == 0) return;
// if(g[v].size() == 0){
// s[v].pb({v, COL[v]});
// return;
// }
// if(g[v].size() == 1){
// s[v].pb({v, COL[v]});
// for(auto u: s[g[v][0][0]]) s[v].pb(u);
// return;
// }
// int ptx = 0, pty = 0;
// array<int, 2> pt = {0, 0};
// s[v].pb(v);
// int x = g[v][0][0], y = g[v][1][0];
// int num = s[x].size() + s[y].size();
// while(num > 0){
// if(ptx == g[x].size()){
// s[v].pb({s[y][pty]});
// pty++;
// }else if(pty == g[y].size()){
// s[v].pb({s[x][ptx]});
// ptx++;
// }else{
// if(pt[0] < pt[1]){
// }else{
// }
// }
// int col = s[v].back()[1] - 1, node = s[v].back()[0];
// if(s[v][pt[col]][0] != par[node]){
// ans[v] = 0;
// return;
// }
// num--;
// }
}
vector<int> beechtree(int n, int m, vector<int> P, vector<int> CC){
COL = CC;
for(int i = 1; i < n; ++i){
g[P[i]].pb({i, COL[i]});
}
ans.resize(n);
dep[0] = 0;
dfs(0);
return ans;
}
Compilation message
beechtree.cpp: In function 'void dfs(int)':
beechtree.cpp:18:17: warning: unused variable 'c' [-Wunused-variable]
18 | int u = U[0], c = U[1];
| ^
beechtree.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i = 1; i < s[v].size(); ++i){
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Execution timed out |
2078 ms |
21084 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 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 |
4 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 |
4 ms |
20936 KB |
Output is correct |
11 |
Correct |
4 ms |
21084 KB |
Output is correct |
12 |
Correct |
5 ms |
21084 KB |
Output is correct |
13 |
Correct |
4 ms |
21084 KB |
Output is correct |
14 |
Correct |
4 ms |
21084 KB |
Output is correct |
15 |
Correct |
4 ms |
21084 KB |
Output is correct |
16 |
Correct |
4 ms |
21084 KB |
Output is correct |
17 |
Correct |
4 ms |
21084 KB |
Output is correct |
18 |
Correct |
5 ms |
21084 KB |
Output is correct |
19 |
Correct |
4 ms |
21084 KB |
Output is correct |
20 |
Correct |
4 ms |
21084 KB |
Output is correct |
21 |
Correct |
4 ms |
21084 KB |
Output is correct |
22 |
Correct |
5 ms |
21080 KB |
Output is correct |
23 |
Correct |
4 ms |
21084 KB |
Output is correct |
24 |
Correct |
4 ms |
21084 KB |
Output is correct |
25 |
Correct |
4 ms |
21084 KB |
Output is correct |
26 |
Correct |
4 ms |
21084 KB |
Output is correct |
27 |
Correct |
4 ms |
21084 KB |
Output is correct |
28 |
Correct |
4 ms |
21080 KB |
Output is correct |
29 |
Correct |
4 ms |
21084 KB |
Output is correct |
30 |
Correct |
4 ms |
20888 KB |
Output is correct |
31 |
Correct |
5 ms |
20948 KB |
Output is correct |
32 |
Correct |
4 ms |
21096 KB |
Output is correct |
33 |
Correct |
4 ms |
21096 KB |
Output is correct |
34 |
Correct |
4 ms |
21096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 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 |
Execution timed out |
2056 ms |
82528 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2036 ms |
21084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21080 KB |
Output is correct |
2 |
Correct |
4 ms |
21084 KB |
Output is correct |
3 |
Correct |
4 ms |
21336 KB |
Output is correct |
4 |
Correct |
4 ms |
21084 KB |
Output is correct |
5 |
Execution timed out |
2056 ms |
82528 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Execution timed out |
2078 ms |
21084 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21080 KB |
Output is correct |
2 |
Correct |
4 ms |
21084 KB |
Output is correct |
3 |
Correct |
4 ms |
21336 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 |
20936 KB |
Output is correct |
7 |
Correct |
4 ms |
21084 KB |
Output is correct |
8 |
Correct |
5 ms |
21084 KB |
Output is correct |
9 |
Correct |
4 ms |
21084 KB |
Output is correct |
10 |
Correct |
4 ms |
21084 KB |
Output is correct |
11 |
Correct |
4 ms |
21084 KB |
Output is correct |
12 |
Correct |
4 ms |
21084 KB |
Output is correct |
13 |
Correct |
4 ms |
21084 KB |
Output is correct |
14 |
Correct |
5 ms |
21084 KB |
Output is correct |
15 |
Correct |
4 ms |
21084 KB |
Output is correct |
16 |
Correct |
4 ms |
21084 KB |
Output is correct |
17 |
Correct |
4 ms |
21084 KB |
Output is correct |
18 |
Correct |
5 ms |
21080 KB |
Output is correct |
19 |
Correct |
4 ms |
21084 KB |
Output is correct |
20 |
Correct |
4 ms |
21084 KB |
Output is correct |
21 |
Correct |
4 ms |
21084 KB |
Output is correct |
22 |
Correct |
4 ms |
21084 KB |
Output is correct |
23 |
Correct |
4 ms |
21084 KB |
Output is correct |
24 |
Correct |
4 ms |
21080 KB |
Output is correct |
25 |
Correct |
54 ms |
41580 KB |
Output is correct |
26 |
Execution timed out |
2041 ms |
33104 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Execution timed out |
2078 ms |
21084 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21080 KB |
Output is correct |
2 |
Correct |
4 ms |
21084 KB |
Output is correct |
3 |
Correct |
4 ms |
21336 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 |
20936 KB |
Output is correct |
7 |
Correct |
4 ms |
21084 KB |
Output is correct |
8 |
Correct |
5 ms |
21084 KB |
Output is correct |
9 |
Correct |
4 ms |
21084 KB |
Output is correct |
10 |
Correct |
4 ms |
21084 KB |
Output is correct |
11 |
Correct |
4 ms |
21084 KB |
Output is correct |
12 |
Correct |
4 ms |
21084 KB |
Output is correct |
13 |
Correct |
4 ms |
21084 KB |
Output is correct |
14 |
Correct |
5 ms |
21084 KB |
Output is correct |
15 |
Correct |
4 ms |
21084 KB |
Output is correct |
16 |
Correct |
4 ms |
21084 KB |
Output is correct |
17 |
Correct |
4 ms |
21084 KB |
Output is correct |
18 |
Correct |
5 ms |
21080 KB |
Output is correct |
19 |
Correct |
4 ms |
21084 KB |
Output is correct |
20 |
Correct |
4 ms |
21084 KB |
Output is correct |
21 |
Correct |
4 ms |
21084 KB |
Output is correct |
22 |
Correct |
4 ms |
21084 KB |
Output is correct |
23 |
Correct |
4 ms |
21084 KB |
Output is correct |
24 |
Correct |
4 ms |
21080 KB |
Output is correct |
25 |
Correct |
54 ms |
41580 KB |
Output is correct |
26 |
Execution timed out |
2041 ms |
33104 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Execution timed out |
2078 ms |
21084 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |