Pagini recente » Cod sursa (job #2153255) | Cod sursa (job #1656313) | Cod sursa (job #270546) | Cod sursa (job #968639) | Cod sursa (job #1736689)
#include <fstream>
#include <cstdio>
#include <math.h>
#include <algorithm>
using namespace std;
#define llu long long unsigned
#define ll long long
#define pb push_back
#define mp make_pair
//string problemName = "home";
//string inFile = problemName+".in";
//string outFile = problemName+".out";
//ifstream fin(inFile.c_str());
//ofstream fout(outFile.c_str());
const int N = 1030;
bool H[N], L[N], ap1[N], ap2[N];
int main(){
freopen("balanta.in", "r", stdin);
freopen("balanta.out", "w", stdout);
int n,m,i,k,r,j,x;
scanf("%d %d", &n, &m);
for(i = 1;i <= n;i++){
H[i] = L[i] = 1;
}
for(i = 1;i <= m;i++){
scanf("%d", &k);
for(j = 1;j <= k;j++){
scanf("%d", &x);
ap1[x] = 1;
}
for(j = 1;j <= k;j++){
scanf("%d", &x);
ap2[x] = 1;
}
scanf("%d", &r);
if(r == 0){
for(j = 1;j <= n;j++){
H[j] = H[j]&(ap1[j]^1);
H[j] = H[j]&(ap2[j]^1);
L[j] = L[j]&(ap1[j]^1);
L[j] = L[j]&(ap2[j]^1);
ap1[j] = ap2[j] = 0;
}
}else if(r == 1){
for(j = 1;j <= n;j++){
H[j] = H[j]&ap1[j];
L[j] = L[j]&ap2[j];
ap1[j] = ap2[j] = 0;
}
}else{
for(j = 1;j <= n;j++){
H[j] = H[j]&ap2[j];
L[j] = L[j]&ap1[j];
ap1[j] = ap2[j] = 0;
}
}
}
int cnt1, cnt2, nr1, nr2;
cnt1 = cnt2 = 0;
for(i = 1;i <= n;i++){
if(H[i]){
cnt1 += H[i];
nr1 = i;
}
if(L[i]){
cnt2 += L[i];
nr2 = i;
}
}
if(cnt1 == 1 && cnt2 == 0){
printf("%d", nr1);
}else if(cnt1 == 0 && cnt2 == 1){
printf("%d", nr2);
}else{
printf("0");
}
return 0;
}