#include "beechtree.h"
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp[200100];
vector<int>par,col;
int dep[200100],timesas0[200100],timesas1[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[i])
nods.push_back(K);
return check(nods);
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C){
par=P;
col=C;
vector<int> V(N,1);
for(int i=1;i<N;i++)
if(mp[P[i]][C[i]]++)
V[P[i]]=0,V[P[i]?P[P[i]]:P[i]]=0;
for(int i=N;--i;)
dep[par[i]]=max(dep[par[i]],++dep[i]);
for(int i=N;i--;){
sub[i].push_back(i);
if(P[i]>=0)
for(auto d:sub[i])
sub[P[i]].push_back(d);
}
dep[0]++;
vector<int>VV(N);
iota(VV.begin(),VV.end(),0);
if(V[0]==1)
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++)
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
20312 KB |
Output is correct |
2 |
Incorrect |
7 ms |
20528 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
20316 KB |
Output is correct |
2 |
Incorrect |
7 ms |
20316 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
20316 KB |
Output is correct |
2 |
Incorrect |
7 ms |
20316 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
20568 KB |
Output is correct |
2 |
Correct |
8 ms |
20572 KB |
Output is correct |
3 |
Incorrect |
6 ms |
20568 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
20316 KB |
Output is correct |
2 |
Incorrect |
7 ms |
20316 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
20312 KB |
Output is correct |
2 |
Incorrect |
7 ms |
20528 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
20316 KB |
Output is correct |
2 |
Incorrect |
7 ms |
20316 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
20312 KB |
Output is correct |
2 |
Incorrect |
7 ms |
20528 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
20316 KB |
Output is correct |
2 |
Incorrect |
7 ms |
20316 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
20312 KB |
Output is correct |
2 |
Incorrect |
7 ms |
20528 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |