Pagini recente » Cod sursa (job #1216177) | Cod sursa (job #1666661) | Cod sursa (job #57001) | Cod sursa (job #219522) | Cod sursa (job #3188882)
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("balanta.in");
ofstream fout("balanta.out");
int n, m, x, r, sol, sum;
int G[1040], U[1040], A[1040], B[1040], ok[1040];
int main(){
fin >> n >> m;
for (int i = 1; i <= n; i++){
G[i] = 1;
U[i] = 1;
}
for(int i = 1; i <= m; i++){
fin >> x;
for(int j = 1; j <= x; j++)
fin >> A[j];
for(int j = 1; j <= x; j++)
fin >> B[j];
fin >> r;
if ( r == 0 ){
for(int j = 1; j <= x; j++){
G[ A[j] ] = 0;
G[ B[j] ] = 0;
U[ A[j] ] = 0;
U[ B[j] ] = 0;
/// G - A - B /// U - A - B
}
continue;
}
if ( r == 1 ){
memset(ok, 0, sizeof(ok));
for(int j = 1; j <= x; j++)
ok[ A[j] ] = 1;
for(int j = 1; j <= n; j++){
if ( ok[j] == 1 && G[j] == 1 )
G[j] = 1;
else
G[j] = 0;
}
memset(ok, 0, sizeof(ok));
for(int j = 1; j <= x; j++)
ok[ B[j] ] = 1;
for(int j = 1; j <= n; j++){
if ( ok[j] == 1 && U[j] == 1 )
U[j] = 1;
else
U[j] = 0;
}
continue;
}
if ( r == 2 ){
memset(ok, 0, sizeof(ok));
for(int j = 1; j <= x; j++)
ok[ B[j] ] = 1;
for(int j = 1; j <= n; j++){
if ( ok[j] == 1 && G[j] == 1 )
G[j] = 1;
else
G[j] = 0;
}
memset(ok, 0, sizeof(ok));
for(int j = 1; j <= x; j++)
ok[ A[j] ] = 1;
for(int j = 1; j <= n; j++){
if ( ok[j] == 1 && U[j] == 1 )
U[j] = 1;
else
U[j] = 0;
}
continue;
}
}
sum = 0;
sol = -1;
for(int i = 1; i <= n; i++) {
if ( G[i] == 1 )
sol = i;
sum += G[i];
}
for(int i = 1; i <= n; i++) {
if ( U[i] == 1 )
sol = i;
sum += U[i];
}
if ( sol != -1 && sum == 1 )
fout << sol;
else
fout << 0;
return 0;
}