Submission #832206

#TimeUsernameProblemLanguageResultExecution timeMemory
832206tranxuanbachSplit the Attractions (IOI19_split)C++17
7 / 100
54 ms11264 KiB
#include "split.h"

#include <bits/stdc++.h>
using namespace std;

#define isz(a) ((signed)a.size())

const int N = 1e5 + 5, M = 2e5 + 5;

int n, m;
int a, b, c;
vector <int> adj[N];

vector <int> ans;

namespace subtask1{
	bool check(){
		for (int u = 0; u < n; u++){
			if (isz(adj[u]) > 2){
				return false;
			}
		}
		return true;
	}

	vector <bool> chosen;

	void dfs(int u){
		chosen[u] = true;
		if (a){
			ans[u] = 1;
			a--;
		}
		else if (b){
			ans[u] = 2;
			b--;
		}
		else{
			ans[u] = 3;
			c--;
		}
		for (auto v: adj[u]){
			if (chosen[v]){
				continue;
			}
			dfs(v);
		}
	}

	vector <int> solve(){
		chosen.assign(n, false);

		int s = 0;
		for (int u = 1; u < n; u++){
			if (isz(adj[u]) == 1){
				s = u;
				break;
			}
		}
		dfs(s);
		return ans;
	}
}

vector <int> find_split(int _n, int _a, int _b, int _c, vector <int> _u, vector <int> _v){
	n = _n; m = isz(_u); a = _a; b = _b; c = _c;
	for (int i = 0; i < m; i++){
		int u = _u[i], v = _v[i];
		adj[u].emplace_back(v);
		adj[v].emplace_back(u);
	}
	ans.assign(n, 0);
 
	if (subtask1::check()){
		return subtask1::solve();
	}
	assert(false);
}
#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...