Cod sursa(job #2434193)

Utilizator memecoinMeme Coin memecoin Data 30 iunie 2019 23:07:36
Problema Balanta Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string.h> 
#include <string>

using namespace std;

ifstream fin("balanta.in");
ofstream fout("balanta.out");

int low[2024];
int high[2024];
int a[2024];
int b[2024];

int main() {

	int n, t;

	fin >> n >> t;

	for (int i = 1; i <= n; ++i) {
		low[i] = 1;
		high[i] = 1;
	}

	while (t > 0) {
		int m, r;

		fin >> m;

		for (int i = 0; i < m; ++i) {
			fin >> a[i];
		}
		for (int i = 0; i < m; ++i) {
			fin >> b[i];
		}

		fin >> r;

		for (int i = 0; i < m; ++i) {
			if (r == 0) {
				high[a[i]] = 0;
				low[a[i]] = 0;
				high[b[i]] = 0;
				low[b[i]] = 0;
			}
			if (r == 1) {
				for (int i = 0; i < m; ++i) {
					low[a[i]] = 0;
					high[b[i]] = 0;
				}
			}
			if (r == 2) {
				for (int i = 0; i < m; ++i) {
					high[a[i]] = 0;
					low[b[i]] = 0;
				}
			}
		}

		t--;
	}

	int nh = 0;
	int nl = 0;

	for (int i = 1; i <= n; ++i) {
		nl += low[i];
		nh += high[i];
	}

	if (nh == 1 && nl != 1) {
		for (int i = 1; i <= n; ++i) {
			if (high[i]) {
				fout << i;
				return 0;
			}
		}
	}

	if (nh != 1 && nl == 1) {
		for (int i = 1; i <= n; ++i) {
			if (low[i]) {
				fout << i;
				return 0;
			}
		}
	}

	fout << "0";

	return 0;
}