Submission #433532

#TimeUsernameProblemLanguageResultExecution timeMemory
433532JUANDI321Split the Attractions (IOI19_split)C++17
7 / 100
88 ms9372 KiB
#include "split.h"
#include <vector>
#include <iostream>

using namespace std;
vector<vector<int>> g(100100);
vector<int> rest(100100);
int aa, bb, cc;
bool ch[100100];
void dfs(int node)
{
	if(ch[node])return;
	ch[node]=true;
	if(aa>0)
	{
		rest[node]=1;
		aa--;
	}
	else if(bb>0)
	{
		rest[node]=2;
		bb--;
	}
	else 
	{
		rest[node]=3;
		cc--;
	}
	for(int y : g[node])
	{
		if(!ch[y])
		{
			//cout<<y<<" "<<node<<endl;
			dfs(y);
			break;
		}
	}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) 
{
	aa = a;
	bb = b;
	cc = c;
	vector<int> res(n);
	int m = p.size();
	for(int i = 0; i<m; i++)
	{
		g[p[i]].push_back(q[i]);
		g[q[i]].push_back(p[i]);
	}
	int node = 0;
	if(m==n-1)
	{
		for(int i = 0; i<n; i++)
		{
			if(g[i].size() == 1)
			{
				node = i; 
				break;
			}
		}
	}
	dfs(node);
	for(int i = 0; i<n; i++)
	{//cout<<"HOLA"<<endl;
		res[i] = rest[i];
		
	}
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...