Cod sursa(job #1181636)

Utilizator denisx304Visan Denis denisx304 Data 3 mai 2014 13:50:16
Problema Party Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Semestrul 2 Marime 1.26 kb
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
ifstream f("party.in");
ofstream g("party.out");
#define nmax 105

int n, m, sol;
bool val[nmax];

struct party
{
    int x, y, z;
    bool ok;
    void makeok()
    {
        if (z == 0)
            ok = val[x] || val[y];
        if (z == 1)
            ok = val[x] || !val[y];
        if (z == 2)
            ok = !val[x] || val[y];
        if (z == 3)
            ok = !val[x] || !val[y];
    }
} p[1005];

bool valid()
{
    for (int i = 0; i < m; i ++)
    {
        p[i].makeok();
        if (!p[i].ok)
        {
            bool loto = rand() % 2;
            if (loto)
                val[p[i].x] = !val[p[i].x];
            else
                val[p[i].y] = !val[p[i].y];
            return false;
        }
    }
    return true;
}

int main()
{
    f >> n >> m;
    for (int i = 0; i < m; i ++)
        f >> p[i].x >> p[i].y >> p[i].z;
    for (int i = 1; i <= n; i ++)
        val[i] = rand() % 2;
    while (!valid());
    for (int i = 1; i <= n; i ++)
        sol += val[i];
    g << sol << '\n';
    for (int i = 1; i <= n; i ++)
        if (val[i])
            g << i << '\n';

    f.close();
    g.close();
    return 0;

}