Cod sursa(job #2218850)
Utilizator | Data | 6 iulie 2018 00:16:59 | |
---|---|---|---|
Problema | Balanta | Scor | 70 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 2.76 kb |
#include <fstream>
#define NMAX 1025
using namespace std;
ifstream cin("balanta.in");
ofstream cout("balanta.out");
int n, m, k, st[NMAX], dr[NMAX], ans[NMAX], x, ct, r;
bool sem = true;
int main()
{
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
cin >> k;
for(int j = 1; j <= k; j++)
cin >> st[j];
for(int j = 1; j <= k; j++)
cin >> dr[j];
cin >> r;
if(sem)
for(int j = 1; j <= k; j++)
{
ct = 0;
if(r == 0)
ans[st[j]] = -1, ans[dr[j]] = -1;
else
if(r == 1)
{
if(ans[st[j] == 2])
ans[st[j]] = -1;
else
if(ans[st[j]] == 0)
ans[st[j]] = 1;
if(ans[dr[j]] == 1)
ans[dr[j]] = -1;
else
if(ans[dr[j]] == 0)
ans[dr[j]] = 2;
if(ans[st[j]] == 1)
ct++, x = st[j];
if(ans[dr[j]] == 2)
ct++, x = dr[j];
}
else
if(r == 2)
{
if(ans[st[j]] == 1)
ans[st[j]] = -1;
else
if(ans[st[j]] == 0)
ans[st[j]] = 2;
if(ans[dr[j]] == 2)
ans[dr[j]] = -1;
else
if(ans[dr[j]] == 0)
ans[dr[j]] = 1;
if(ans[st[j]] == 2)
ct++, x = st[j];
if(ans[dr[j]] == 1)
ct++, x = dr[j];
}
}
if(r != 0)
for(int p = 1; p <= n; p++)
{
bool ok = true;
for(int j = 1; j <= k; j++)
if(p == st[j] || p == dr[j])
ok = false;
if(ok)
ans[p] = -1;
}
if(ct == 1)
{
sem = false;
}
}
ct = 0;
if(sem)
{
for(int i = 1; i <= n; i++)
if(ans[i] != -1)
ct++, x = i;
if(ct == 1)
cout << x;
else
cout << 0;
}
else
cout << x;
return 0;
}