Cod sursa(job #1489124)

Utilizator KusikaPasa Corneliu Kusika Data 20 septembrie 2015 17:18:07
Problema Party Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
#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";;
}