# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
987407 | activedeltorre | Beech Tree (IOI23_beechtree) | C++17 | 2045 ms | 20180 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 <vector>
#include <queue>
#include <iostream>
#include <map>
using namespace std;
vector<int>cop[200005];
int cul[200005];
int imp[200005];
int dist[200005];
int par[200005];
vector<int>vecus;
bool cmp(int a,int b)
{
//if(dist[a]==dist[b])
// {
return cop[a].size()>cop[b].size();
// }
// return dist[a]<dist[b];
}
map<int,int>mp;
map<int,int>mp2;
int calc(int curr)
{
mp2.clear();
int cur;
queue<int>qu;
dist[curr]=0;
qu.push(curr);
vecus.clear();
while(qu.size())
{
cur=qu.front();
vecus.push_back(cur);
qu.pop();
for(auto k:cop[cur])
{
dist[k]=dist[curr]+1;
qu.push(k);
}
}
//cout<<curr<<" "<<imp[curr]<<" :";
for(auto i:vecus)
{
if(i!=curr)
{
if(par[i]!=vecus[mp2[cul[i]]])
{
return 0;
}
mp2[cul[i]]++;
}
}
// cout<<'\n';
return 1;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C)
{
int n=N,culs=M,i;
vector<int>ans;
for(i=1;i<n;i++)
{
par[i]=P[i];
cop[P[i]].push_back(i);
cul[i]=C[i];
}
for(i=0;i<n;i++)
{
mp.clear();
for(auto k:cop[i])
{
mp[cul[k]]++;
if(mp[cul[k]]==2)
{
imp[i]=1;
}
}
}
for(i=0;i<n ;i++)
{
ans.push_back(calc(i));
}
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... |