Cod sursa(job #2074786)

Utilizator andrei20003Ionescu Andrei andrei20003 Data 24 noiembrie 2017 23:52:36
Problema Party Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <fstream>

using namespace std;

ifstream cin("party.in");
ofstream cout("party.out");

struct cerinta {
    int x, y, z;
}A[124];

int P[128],N,M,ok,i,X,Y,Z,Cnt;

int main() {
    cin>>N>>M;
    for (i=1;i<=N;i++)
        P[i]=1;
    for(i=1;i<=M;i++)
        cin>>A[i].x>>A[i].y>>A[i].z;
    ok=0;
    while(ok==0){
        ok=1;
        for (i=1;i<=M;i++){
            X=A[i].x, Y=A[i].y, Z=A[i].z;
            if(Z==0)
                if(P[X]==0 && P[Y]==0){
                    P[X]=1;
                    P[Y]=1;
                    ok=0;
                    break;
                }
            if(Z==1)
                if(P[X]==0 && P[Y]!=0){
                    P[Y]=0;
                    ok=0;
                    break;
                }
            if(Z==2)
                if(P[Y]==0 && P[X]!=0){
                    P[X]=0;
                    ok=0;
                    break;
                }
            if(Z==3)
                if(P[X]==1 && P[Y]==1){
                    P[Y]=0;
                    ok=0;
                    break;
                }
            }
    }
    for(i=1;i<=N;i++)
        if(P[i])Cnt++;
            cout<<Cnt<<endl;
    for(i=1;i<=N;i++)
        if(P[i])
            cout<<i<<endl;
    return 0;
}