Pagini recente » Cod sursa (job #923638) | Cod sursa (job #1058761) | Cod sursa (job #2160306) | Cod sursa (job #286780) | Cod sursa (job #177875)
Cod sursa(job #177875)
#include <fstream>
#include <utility>
#include <stdlib.h>
#include <vector>
using namespace std;
#define maxn 1001
#define FOR(i,a,b) for (i = (a); i <= (b); i++)
#define sz size()
#define pb push_back
#define mp make_pair
#define s second
#define f first
int N, M, bad;
int v[maxn], c[maxn];
vector<pair<int, int> > exp;
int eval(int pos)
{
pair<int, int> e = exp[pos];
if (c[pos] == 0)
return (v[e.f] || v[e.s]);
if (c[pos] == 1)
return (v[e.f] || !v[e.s]);
if (c[pos] == 2)
return (!v[e.f] || v[e.s]);
if (c[pos] == 3)
return (!v[e.f] || !v[e.s]);
}
int extra()
{
int i;
FOR(i, 1, N)
if (v[i]) return 1;
return 0;
}
int main()
{
int i, x, y, pas;
ifstream fin("party.in");
ofstream fout("party.out");
fin >> N >> M;
FOR(i, 0, M - 1)
{
fin >> x >> y >> c[i];
exp.pb(mp(x, y));
}
/* FOR(i, 0, M - 1)
fout << exp[i].f << " " << exp[i].s << " " << c[i] << '\n';*/
FOR(pas, 0, 10000)
{
int ok = eval(0);
if (!eval(0)) bad = 0;
FOR(i, 1, M - 1)
{
ok = ok && eval(i);
if (!eval(i)) bad = i;
}
if (ok && extra()) break;
v[exp[bad].f] = !v[exp[bad].f];
}
int res = 0;
for (i = 1; i <= N; i++)
if (v[i]) res++;
fout << res << '\n';
FOR(i, 1, N)
if (v[i]) fout << i << '\n';
fin.close(), fout.close();
}