Pagini recente » Cod sursa (job #3205133) | Cod sursa (job #2816471) | Cod sursa (job #2869101) | Cod sursa (job #1080893) | Cod sursa (job #1225100)
#include <fstream>
//#include <iostream>
using namespace std;
ifstream fin ("balanta.in");
ofstream fout ("balanta.out");
const int N = 1024;
int n, m, v[N], w[N], now[N], sol, nr;
int main() {
fin >> n >> m;
for (int x, type, i = 1; i <= m; ++i) {
fin >> x;
for (int j = 0; j < (x << 1); ++j)
fin >> w[j];
fin >> type;
if (!type)
for (int j = 0; j < x; ++j)
v[w[j]] = 3;
else {
if (type == 1) {
for (int j = 0; j < x; ++j) {
if (!v[w[j]])
v[w[j]] = 1;
if (v[w[j]] == 2)
v[w[j]] = 3;
now[w[j]] = i;
}
for (int j = x; j < (x << 1); ++j) {
if (!v[w[j]])
v[w[j]] = 2;
if (v[w[j]] == 1)
v[w[j]] = 3;
now[w[j]] = i;
}
}
if (type == 2) {
for (int j = x; j < (x << 1); ++j) {
if (!v[w[j]])
v[w[j]] = 1;
if (v[w[j]] == 2)
v[w[j]] = 3;
now[w[j]] = i;
}
for (int j = 0; j < x; ++j) {
if (!v[w[j]])
v[w[j]] = 2;
if (v[w[j]] == 1)
v[w[j]] = 3;
now[w[j]] = i;
}
}
for (int j = 1; j <= n; ++j)
if (now[j] < i && (v[j] == 1 || v[j] == 2))
v[j] = 3;
}
/*cout << i << ": ";
for (int j = 1; j <= n; ++j)
cout << v[j] << " ";
cout << "\n";*/
}
for (int i = 1; i <= n; ++i) {
if (v[i] == 1 || v[i] == 2) {
sol++;
nr = i;
}
}
if (sol != 1)
fout << 0;
else
fout << nr;
}