Cod sursa(job #844311)

Utilizator Theorytheo .c Theory Data 28 decembrie 2012 23:50:31
Problema Party Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
#include<fstream>
#include<stdlib.h>
#include<time.h>
using namespace std;

ifstream fin("party.in");
ofstream fout("party.out");

#define NMAX 102
#define MMAX 1002

int N, M;
bool Friends[NMAX];
struct Relation {int type, x, y;};
Relation R[MMAX];
void read(){
    fin >> N >>M;
    for(int i = 1; i <= M; i++)
        R[i].x >> R[i].y >> R[i].type;

}
bool verifica(int i, bool a, bool b){

    if(R[i].type == 0) return a || b;

    if(R[i].type == 1) return a || !b;

    if(R[i].type == 2) return !a || b;

    if(R[i].type == 3) return a + b != 2;



}
int main(){
    read();

    srand(time(NULL));

    for(int i = 1; i <= N; i++)
        Friends[i] = true;
    int i;

    for(i = 1; i <= M; i++)
        if(!verifica(i, Friends[R[i].x] , Friends[R[i].y])){
            int r = rand() % 2;
            if(r) Friends[R[i].x] = !Friends[R[i].x];
            else  Friends[R[i].y] = !Friends[R[i].y];

            i = 0;
        }
     int Number_Friends = 0;
    for(int i = 1; i <= N; i++)
        if(Friends[i] == true)
            Number_Friends++;

    fout <<Number_Friends <<'\n';

    for(int i = 1; i <= N; i++)
        if(Friends[i] == true)
            fout << i <<'\n';

    return 0;
}