Pagini recente » Cod sursa (job #2380547) | Cod sursa (job #2344004)
#include <fstream>
#include <cstring>
using namespace std;
bool p[101];
bool done = false;
struct Cond
{
int x, y;
unsigned char c;
void processCondition()
{
if (c == 0)
if (!p[x] && !p[y])
{
p[x] = true;
p[y] = true;
done = false;
}
else if (c == 1)
if (!p[x] && p[y])
{
p[y] = false;
done = false;
}
else if (c == 2)
if (!p[y] && p[x])
{
p[x] = false;
done = false;
}
else if (c == 3)
if (p[x] && p[y])
{
p[y] = false;
done = false;
}
}
};
int main()
{
memset(p, true, sizeof(int) * 101);
ifstream input("party.in");
int n, m, i;
Cond cond[1000];
input >> n >> m;
for (i = 0; i < m; i++)
{
Cond &c = cond[i];
input >> c.x >> c.y >> c.c;
}
while (!done)
{
done = true;
for (i = 0; i < m; i++)
cond[i].processCondition();
}
ofstream output("party.out");
int count = 0;
for (i = 1; i <= n; i++)
count++;
output << count << '\n';
for (i = 1; i <= n; i++)
if (p[i])
output << i << '\n';
return 0;
}