Submission #1047596

#TimeUsernameProblemLanguageResultExecution timeMemory
1047596Kel_MahmutSplit the Attractions (IOI19_split)C++14
7 / 100
34 ms14428 KiB
#include "split.h"
#include <bits/stdc++.h>
#define pb push_back
// #define endl ("\n")
#define all(aa) aa.begin(), aa.end()
typedef long long ll;
using namespace std;


vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
	int m = q.size();

	vector<vector<int>> g(n);
	for(int i = 0; i < m; i++){
		g[q[i]].pb(p[i]);
		g[p[i]].pb(q[i]);
	}

	bool chain = 1;
	for(int i = 0; i < n; i++) chain &= (int) g[i].size() <= 2;
	if(chain){
		vector<int> vis(n);
		vector<int> color(n);
		int lim = 0;
		int cnt = 0;
		int komsu;
		function<void(int, int)> dfs = [&](int u, int col){
			cnt++;
			color[u] = col;
			vis[u] = 1;
			if(cnt == lim){
				for(int v : g[u]){
					if(!vis[v]){
						komsu = v;
						return;
					}
				}
				komsu = -1;
				return;
			}
			for(int v : g[u]){
				if(vis[v]) continue;
				dfs(v, col);
				if(cnt == lim) return;
			}
		};
		vector<int> deg1;
		for(int i = 0; i < n; i++) if(g[i].size() == 1) deg1.pb(i);
		lim = a;
		cnt = 0;

		if(deg1.size())
			dfs(deg1[0], 1);
		else{
			for(int i = 0; i < n; i++){
				if(!vis[i]){
					dfs(i, 1);
					break;
				}	
			}
		}

		lim = b; cnt = 0;
		if(deg1.size())
			dfs(deg1[1], 2);
		else{
			assert(komsu != -1);
			dfs(komsu, 2);
		}
		
		lim = c; cnt = 0;
		for(int i = 0; i < n; i++){
			if(!vis[i]){
				dfs(i, 3);
				break;
			}
		}

		return color;	
	}	

	if(a == 1){
		vector<int> vis(n);
		vector<int> color(n);
		int lim = b;
		int cnt = 0;
		function<void(int, int)> dfs = [&](int u, int col){
			cnt++;
			vis[u] = 1;
			color[u] = col;
			if(cnt == lim) return;
			for(int v : g[u]){
				if(vis[v]) continue;
				dfs(v, col);
				if(cnt == lim) return;
			}
		};
		dfs(0, 2);
		for(int i = 0; i < n; i++){
			if(!vis[i]){
				vis[i] = 1;
				color[i] = 1;
			}
		}

		for(int i = 0; i < n; i++){
			if(!vis[i]){
				vis[i] = 1;
				color[i] = 3;
			}
		}
		return color;
	}
}

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:13:25: warning: control reaches end of non-void function [-Wreturn-type]
   13 |  vector<vector<int>> g(n);
      |                         ^
#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...