#include "beechtree.h"
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp[200100];
vector<int>par,col;
int dep[200100];
vector<int>sub[200100],adj[200100];
int check(vector<int>v){
map<int,int>mp;
for(int i=1;i<v.size();i++)
if(v[mp[col[v[i]]]++]!=par[v[i]])
return 0;
return 1;
}
int checkdep2(vector<int>nods){
sort(nods.begin(),nods.end(),[](int a,int b){
return sub[a].size()>sub[b].size();
});
vector<int>otherstuf;
while(sub[nods.back()].size()==1)
otherstuf.push_back(nods.back()),
nods.pop_back();
for(int i=1;i<nods.size();i++)
for(auto K:adj[nods[i]])
if(sub[K].size()==1)
nods.push_back(K);
vector<int>v2{0};
for(auto K:adj[0])
if(sub[K].size()==1)
v2.push_back(K);
nods.erase(nods.begin());
for(auto i:nods)
v2.push_back(i);
return check(v2);
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C){
P[0]=0;
par=P;
col=C;
vector<int> V(N,1);
for(int i=N;--i;) adj[par[i]].push_back(i),
dep[par[i]]=max(dep[par[i]],++dep[i]);
for(int i=N;i--;){
sub[i].push_back(i);
if(P[i]>=0&&dep[i]<=2)
for(auto d:sub[i])
sub[P[i]].push_back(d);
sort(sub[i].begin(),sub[i].end());
if(i)V[i]=check(sub[i]);
}
dep[0]++;
assert(dep[0]<=3);
vector<int>VV(N);
iota(VV.begin(),VV.end(),0);
V[0]=checkdep2(VV);
return V;
}
Compilation message
beechtree.cpp: In function 'int check(std::vector<int>)':
beechtree.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=1;i<v.size();i++)
| ~^~~~~~~~~
beechtree.cpp: In function 'int checkdep2(std::vector<int>)':
beechtree.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=1;i<nods.size();i++)
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
19800 KB |
Output is correct |
2 |
Runtime error |
20 ms |
40280 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
19804 KB |
Output is correct |
2 |
Correct |
9 ms |
20016 KB |
Output is correct |
3 |
Runtime error |
20 ms |
40208 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
19804 KB |
Output is correct |
2 |
Correct |
9 ms |
20016 KB |
Output is correct |
3 |
Runtime error |
20 ms |
40208 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
19804 KB |
Output is correct |
2 |
Correct |
7 ms |
19804 KB |
Output is correct |
3 |
Correct |
9 ms |
19804 KB |
Output is correct |
4 |
Correct |
7 ms |
19804 KB |
Output is correct |
5 |
Correct |
6 ms |
19804 KB |
Output is correct |
6 |
Correct |
7 ms |
19800 KB |
Output is correct |
7 |
Correct |
6 ms |
19804 KB |
Output is correct |
8 |
Correct |
7 ms |
20056 KB |
Output is correct |
9 |
Correct |
8 ms |
19804 KB |
Output is correct |
10 |
Incorrect |
6 ms |
19804 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
19804 KB |
Output is correct |
2 |
Correct |
9 ms |
20016 KB |
Output is correct |
3 |
Correct |
7 ms |
19804 KB |
Output is correct |
4 |
Correct |
6 ms |
19804 KB |
Output is correct |
5 |
Runtime error |
76 ms |
78924 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
19800 KB |
Output is correct |
2 |
Runtime error |
20 ms |
40280 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
19804 KB |
Output is correct |
2 |
Correct |
9 ms |
20016 KB |
Output is correct |
3 |
Correct |
7 ms |
19804 KB |
Output is correct |
4 |
Correct |
6 ms |
19804 KB |
Output is correct |
5 |
Runtime error |
24 ms |
40020 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
19800 KB |
Output is correct |
2 |
Runtime error |
20 ms |
40280 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
19804 KB |
Output is correct |
2 |
Correct |
9 ms |
20016 KB |
Output is correct |
3 |
Correct |
7 ms |
19804 KB |
Output is correct |
4 |
Correct |
6 ms |
19804 KB |
Output is correct |
5 |
Runtime error |
24 ms |
40020 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
19800 KB |
Output is correct |
2 |
Runtime error |
20 ms |
40280 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |