# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
832943 | Marco_Escandon | Split the Attractions (IOI19_split) | C++17 | 622 ms | 1048576 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;
typedef long long ll;
vector<ll> cad[200001];
vector<ll> asd={0,1,2}; vector<ll> d;
vector<int> sol;
vector<int> v;
ll po;
ll dfs2(ll node, ll p)
{
v[node]=0;
for(auto i:cad[node])
{
if(i!=p)
{
v[node]+=dfs2(i,node);
}
}
return 1+v[node];
}
ll dfs(ll node,ll p)
{
if(sol[node]!=0)
return true;
ll pl=true;
for(auto i:cad[node])
{
if(i!=p&&v[i]==d[asd[po]])
{
dfs(i,node);
if(sol[node]==0)
{
while(d[asd[po]]==0)
{
po++;
}
sol[node]=asd[po]+1;
d[asd[po]]--;
}
break;
}
}
for(auto i:cad[node])
{
if(i!=p)
{
if(dfs(i,node)== false)
return false;
//cout<<node<<" "<<sol[node]<<" "<<asd[po]+1<<" "<<d[asd[po]]<<po<<"\n\n";
if(sol[node]!=asd[po]+1 && sol[node]!=0 && d[asd[po]]!=0)
{
//cout<<"asd";
return false;
}
if(sol[node]==0)
{
while(d[asd[po]]==0)
{
po++;
}
sol[node]=asd[po]+1;
d[asd[po]]--;
}
}
}
if(sol[node]==0)
{
if(d[asd[po]]==0)
{
po++;
}
sol[node]=asd[po]+1;
d[asd[po]]--;
}
return true;
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
for(int i=0; i<p.size(); i++)
{
cad[p[i]].push_back(q[i]);
cad[q[i]].push_back(p[i]);
}
v.resize(n);
dfs2(0,-1);
do
{
//cout<<asd[0]<<asd[1]<<asd[2]<<"\n";
sol.assign(n,0);
d.clear();
d.push_back(a);
d.push_back(b);
d.push_back(c);
po=0;
if(dfs(0,-1)==true)
{
return sol;
}
}
while(next_permutation(asd.begin(),asd.end()));
vector<int> no(n,0);
return no;
}
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... |