Cod sursa(job #2106748)

Utilizator brczBereczki Norbert Cristian brcz Data 16 ianuarie 2018 09:49:30
Problema Balanta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.64 kb
#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
#define bg begin
#define nd end
using namespace std;

#define int long long

const int maxn = 100003;
const int maxk = 1003;

set<int> heavy;
set<int> light;
int n,m;
int k;
int a[maxk],b[maxk];
int op;

int32_t main(){

	freopen("balanta.in","r",stdin);
	freopen("balanta.out","w",stdout);

	ios_base::sync_with_stdio(false);
	cin.tie(0);


	cin >> n >> m;

	for(int i=1;i<=n;++i) {
		heavy.insert(i);light.insert(i);
	}
	for(int mi=0;mi<m;++mi) {
		cin >> k;
		for(int i=0;i<k;++i) cin >> a[i];
		for(int i=0;i<k;++i) cin >> b[i];
		cin >> op;
		if(op == 0) {
			for(int i=0;i<k;++i) {
				heavy.erase(a[i]);
				heavy.erase(b[i]);
				light.erase(a[i]);
				light.erase(b[i]);
			}
		}
		if(op == 1) {
			set<int> new_heavy;
			for(int i=0;i<k;++i)
				if(heavy.find(b[i]) != heavy.end()) new_heavy.insert(b[i]);
			heavy = new_heavy;
			set<int> new_light;
			for(int i=0;i<k;++i)
				if(light.find(a[i]) != light.end()) new_light.insert(a[i]);
			light = new_light;
		}
		if(op == 2) {
			set<int> new_heavy;
			for(int i=0;i<k;++i)
				if(heavy.find(a[i]) != heavy.end()) new_heavy.insert(a[i]);
			heavy = new_heavy;
			set<int> new_light;
			for(int i=0;i<k;++i)
				if(light.find(b[i]) != light.end()) new_light.insert(b[i]);
			light = new_light;
		}
	}
	if(heavy.size() == 1 && light.size() == 0) {
		cout << *(heavy.begin()) << '\n';
		return 0;
	}
	if(light.size() == 1 && heavy.size() == 0) {
		cout << *(light.begin()) << '\n';
		return 0;
	}
	cout << 0 << '\n';

	return 0;
}