Pagini recente » Cod sursa (job #1973267) | Cod sursa (job #449492) | Cod sursa (job #2197904) | Cod sursa (job #2545268) | Cod sursa (job #2097410)
#include <fstream>
#define DIM 1030
using namespace std;
ifstream f("balanta.in");
ofstream g("balanta.out");
int n, m, M1[DIM], M2[DIM], x[DIM], y[DIM], nr, tip;
int check(){
int poz1, poz2, poz3, nr1 = 0, nr2 = 0, nr3 = 0;
for(int i = 1; i <= n; ++ i){
if(M1[i] == 1){
poz1 = i;
++ nr1;
}
if(M2[i] == 1){
poz2 = i;
++ nr2;
}
}
if(nr1 == 1 && nr2 == 0)
return poz1;
if(nr2 == 1 && nr1 == 0)
return poz2;
if(nr1 == 1 && nr2 == 1 && poz1 == poz2)
return poz1;
return 0;
}
int main()
{
f>>n>>m;
for(int i = 1; i <= n; ++ i)
M1[i] = M2[i] = 1;
for(int i = 1; i <= m; ++ i){
f>>nr;
for(int j = 1; j <= nr; ++ j)
f>>x[j];
for(int j = 1; j <= nr; ++ j)
f>>y[j];
f>>tip;
if(tip == 0){
for(int j = 1; j <= nr; ++ j)
M1[x[j]] = M1[y[j]] = M2[x[j]] = M2[y[j]] = 0;
}
if(tip == 1){
for(int j = 1; j <= nr; ++ j){
if(M1[x[j]] != 0)
M1[x[j]] = 2;
if(M2[y[j]] != 0)
M2[y[j]] = 2;
}
}
if(tip == 2){
for(int j = 1; j <= nr; ++ j){
if(M1[y[j]] != 0)
M1[y[j]] = 2;
if(M2[x[j]] != 0)
M2[x[j]] = 2;
}
}
for(int i = 1; i <= n; ++ i){
if(tip != 0){
if(M1[i] != 2)
M1[i] = 0;
else
M1[i] = 1;
if(M2[i] != 2)
M2[i] = 0;
else
M2[i] = 1;
}
}
if(check()){
g<<check();
return 0;
}
}
g<<0;
return 0;
}