# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1046474 | Trustfulcomic | Beech Tree (IOI23_beechtree) | C++17 | 2092 ms | 19272 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "beechtree.h"
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int> p,c;
vector<vector<int>> g;
int good(int r){
vector<int> ch;
queue<int> q; q.push(r);
while(!q.empty()){
int n = q.front(); q.pop();
ch.push_back(n);
for (int i : g[n]) q.push(i);
}
if (ch.size() == 1) return 1;
bool jupi = false;
do {
vector<int> count(m, 0);
vector<int> is(ch.size(), -1);
is[0] = r;
bool good = true;
for (int i = 0; i<ch.size() && good; i++){
if (ch[i] == r) continue;
if (p[ch[i]] != is[count[c[ch[i]]]]) good = false;
count[c[ch[i]]]++;
is[i+1]=ch[i];
}
if (good){
jupi = true;
}
} while(next_permutation(ch.begin(), ch.end()));
if (jupi) return 1;
return 0;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C)
{
n = N;
m = M;
p = P;
c = C;
g.resize(n);
for (int i = 1; i<n; i++){
g[p[i]].push_back(i);
}
vector<int> res(n);
for (int i = 0; i<n; i++){
res[i] = good(i);
}
return res;
}
Compilation message (stderr)
# | 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... |