# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
288957 | phillip | Split the Attractions (IOI19_split) | C++14 | 144 ms | 16248 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 "split.h"
#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define pb push_back
using namespace std;
int rv[3],num[3];
vector<int>v[200009];
int vis[200009],col[200009];
void dfs(int x,int par,int id)
{
if(num[id]==0)id++;
if(vis[x])return;
vis[x]=1;
col[x]=rv[id];
num[id]--;
for(int i=0;i<v[x].size();i++)
{
int y=v[x][i];
if(y==par)continue;
dfs(y,x,id);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q)
{
vector<int> res;
num[0]=a;
num[1]=b;
num[2]=c;
int mx=max(a,max(b,c));
int mn=min(a,min(b,c));
for(int i=0;i<3;i++)
{
if(num[i]==mx)
{
//cout<<i<<" ";
rv[2]=i+1;
if(num[(i+1)%3]==mn){rv[0]=(i+1)%3+1;rv[1]=(i+2)%3+1;}
else {rv[1]=(i+1)%3+1;rv[0]=(i+2)%3+1;}
break;
}
}
sort(num,num+3);
for(int i=0;i<p.size();i++)
{
v[p[i]].pb(q[i]);
v[q[i]].pb(p[i]);
}
int rt=0;
for(int i=0;i<n;i++)
{
if(v[i].size()==1)
{
rt=i;
break;
}
}
dfs(rt,rt,0);
for(int i=0;i<n;i++)res.push_back(col[i]);
//cout<<rv[0]<<" "<<rv[1]<<" "<<rv[2]<<"\n";
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... |