#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];
sort(v.begin()+1,v.end());
if(v.size() == 1)ans[now] = 1;
else 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:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i = 1;i<v.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15196 KB |
Output is correct |
2 |
Runtime error |
17 ms |
30704 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
15196 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
15196 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
17 ms |
30552 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
15196 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15196 KB |
Output is correct |
2 |
Runtime error |
17 ms |
30704 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
15196 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15196 KB |
Output is correct |
2 |
Runtime error |
17 ms |
30704 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
15196 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15196 KB |
Output is correct |
2 |
Runtime error |
17 ms |
30704 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |