#include "beechtree.h"
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define vll vector<ll>
#define sd second
#define ft first
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define pll pair<ll, ll>
#define mod 1000000007
#define _set tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update>
#define inf (ll)1e15
#define db(x) cout<<#x<<" : "<<x<<endl;
#define PRESICION(x) cout.setf(ios::fixed,ios::floatfield); cout.precision(x);
using namespace std;
using namespace __gnu_pbds;
ll dx[]={1, -1, 0, 0};
ll dy[]={0, 0, 1, -1};
inline ll sm(ll a, ll b){
return ((a%mod)+(b%mod))%mod;
}
inline ll ml(ll a, ll b){
return ((a%mod)*(b%mod))%mod;
}
inline ll rs(ll a, ll b){
return ((a%mod)-(b%mod)+mod)%mod;
}
ll bpow(ll a , ll b) {
if (b==0)return 1;
if (b%2!=0)return ((bpow(a, b-1)%mod)*(a%mod))%mod;
ll r=bpow (a ,b/ 2) ;
return ((r%mod)*(r%mod))%mod;
}
vector<vector<ll>> res, adj;
inline void dfs(ll n, ll p){
//db(n)
for(auto y: adj[n]){
if(y==p)continue;
dfs(y, n);
for(auto x: res[y])res[n].push_back(x);
res[n].push_back(y);
}
}
inline bool check(vector<int>& C, vector<int>& P, vector<ll>& v1){
vector<ll> v(501, 0);
bool n=1;
for(int i=1; i<v1.size(); i++){
if(v1[v[C[v1[i]]]]!=P[v1[i]])n=0;
v[C[v1[i]]]++;
}
return n;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){
vector<int> res1(N, 0);
vector<vector<ll>>().swap(adj);
vector<vector<ll>>().swap(res);
adj.resize(N+1);
res.resize(N+1);
for(int i=1; i<N; i++){
adj[P[i]].push_back(i);
}
dfs(0, 0);
/*for(int i=0; i<N; i++){
cout<<i<<endl;
for(auto y: res[i])cout<<y<<" ";
cout<<endl;
}*/
for(int i=0; i<N; i++)sort(all(res[i]));
for(int i=0; i<N; i++){
reverse(all(res[i]));
res[i].push_back(i);
reverse(all(res[i]));
if(check(C, P, res[i]))res1[i]=1;
reverse(all(res[i]));
res[i].pop_back();
reverse(all(res[i]));
while(next_permutation(all(res[i]))){
reverse(all(res[i]));
res[i].push_back(i);
reverse(all(res[i]));
if(check(C, P, res[i]))res1[i]=1;
reverse(all(res[i]));
res[i].pop_back();
reverse(all(res[i]));
}
}
return res1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |