Cod sursa(job #2239574)

Utilizator theodor.moroianuTheodor Moroianu theodor.moroianu Data 11 septembrie 2018 10:33:17
Problema Felinare Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <bits/stdc++.h>
using namespace std;

ifstream in("felinare.in");
ofstream out("felinare.out");

int g_in[100010], g_out[100010];

int main()
{
	int n, m, a, b;
	in >> n >> m;
	
	while (m--) {
		in >> a >> b;
		g_in[b]++;
		g_out[a]++;
	}

	int beg = 0, end = 0;
	
	for (int i = 1; i <= n; i++)
		beg += (g_out[i] == 0), end += (g_in[i] == 0);

	out << max(n + beg, n + end) << '\n';

	if (n + beg >= n + end) {
		for (int i = 1; i <= n; i++)
			out << 1 + (g_out[i] == 0 ? 2 : 0) << '\n';
	}
	else {
		for (int i = 1; i <= n; i++)
			out << 2 + (g_in[i] == 0 ? 1 : 0) << '\n';
	}
	return 0;
}