Pagini recente » Cod sursa (job #2843047) | Cod sursa (job #1005076) | Cod sursa (job #1596546) | Cod sursa (job #484853) | Cod sursa (job #1467751)
#include <iostream>
#include <fstream>
using namespace std;
int a[1000][3], n, m;
bool v[100]={0};
void Conditie()
{
int var = 0, x1, x2, i;
bool cond = false;
for (i = 0; i < m; i++)
{
x1 = a[i][0] - 1;
x2 = a[i][1] - 1;
while (cond == false)
{
var++;
switch (a[i][2])
{
case 0: if (v[x1] || v[x2]) cond = true; else cond = false; break;
case 1: if ((v[x1] && v[x2]) || (v[x1] && !v[x2]) || (!v[x1] && !v[x2])) cond = true; else cond = false; break;
case 2: if (v[x1] || v[x2]) cond = true; else cond = false; break;
case 3: if (!v[x1] || !v[x2]) cond = true; else cond = false; break;
}
if (var == 2 || var == 4) v[x1] = !v[x1];
else if (var == 3) {v[x1] = !v[x1]; v[x2] = !v[x2];}
}
if (var > 1) {Conditie; break;}
}
}
main()
{
ifstream f1("party.in");
ofstream f2("party.out");
int i, k = 0;
f1 >> n >> m;
for (i = 0; i < m; i++)
f1 >> a[i][0] >> a[i][1] >> a[i][2];
for (i = 0; i < 100; i++)
v[i] = true;
Conditie;
for (i = 0; i < n; i++)
if (v[i] == true) k++;
f2 << k << "\n";
for (i = 0; i < n; i++)
if (v[i] == true) f2 << i + 1 << "\n";;
}