# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1072904 | MuhammadSaram | Beech Tree (IOI23_beechtree) | C++17 | 57 ms | 6740 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 <bits/stdc++.h>
using namespace std;
const int M = 2000;
vector<int> nei[M];
int col[M],par[M],s[M],t;
bool pos[M];
void dfs(int u)
{
s[u]=++t;
for (int i:nei[u])
dfs(i);
vector<int> v;
for (int i=0;i<M;i++)
if (!s[i])
break;
else if(s[i]>=s[u])
v.push_back(i);
sort(v.begin(),v.end());
do
{
if (v[0]!=u)
continue;
map<int,int> cnt;
bool b=1;
for (int j=1;j<v.size() && b;j++)
{
int i=v[j];
if (v[cnt[col[i]]]!=par[i])
b=0;
else
cnt[col[i]]++;
}
if (b)
{
pos[u]=1;
break;
}
}while(next_permutation(v.begin(),v.end()));
}
vector<int> beechtree(int n, int m, vector<int> p, vector<int> c)
{
vector<int> ans(n);
if (n<=8)
{
for (int i=0;i<n;i++)
col[i]=c[i],par[i]=p[i];
for (int i=1;i<n;i++)
nei[p[i]].push_back(i);
dfs(0);
for (int i=0;i<n;i++)
ans[i]=pos[i];
return ans;
}
set<int> se;
for (int i=n-1;i>=0;i--)
{
ans[i]=1;
se.insert(c[i]);
if (se.size()==2)
break;
}
return ans;
}
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... |