이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
struct ari{
int node, c;
};
int n, m, maxlevel=0;
int buc[200000];
bool used[200000];
bool ya=0;
ari papa[200000];
vector<vector<ari>> adj;
vector<int> perm, nums;
void busca(int node){
nums.push_back(node);
for(auto h: adj[node]){
busca(h.node);
}
}
void nextperm(int pos){
if(ya)
return;
if(pos==nums.size()){
for(int i=1; i<perm.size(); i++){
if(perm[buc[papa[perm[i]].c]]!=papa[perm[i]].node)
return;
buc[papa[perm[i]].c]++;
}
ya=1;
return;
}
for(int i=0; i<nums.size() && ya==0; i++){
if(used[nums[i]])
continue;
used[nums[i]]=1;
perm[pos]=nums[i];
nextperm(pos+1);
used[nums[i]]=0;
if(pos==0)
return;
}
}
bool checa(int node){
busca(node);
perm.clear();
perm.resize(nums.size());
nextperm(0);
return ya;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){
n=N, m=M;
adj.resize(n);
for(int i=1; i<n; i++){
adj[P[i]].push_back({i, C[i]});
papa[i]={P[i], C[i]};
}
vector<int> ans(n);
for(int i=0; i<n; i++){
nums.clear();
ya=0;
if(checa(i))
ans[i]=1;
for(int j=0; j<=m; j++)
buc[j]=0;
for(int i=0; i<n; i++)
used[i]=0;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
beechtree.cpp: In function 'void nextperm(int)':
beechtree.cpp:28:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(pos==nums.size()){
| ~~~^~~~~~~~~~~~~
beechtree.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=1; i<perm.size(); i++){
| ~^~~~~~~~~~~~
beechtree.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0; i<nums.size() && ya==0; i++){
| ~^~~~~~~~~~~~
# | 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... |