Cod sursa(job #844278)

Utilizator Theorytheo .c Theory Data 28 decembrie 2012 23:18:02
Problema Party Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.92 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;

}

int main(){
    read();

    srand(time(NULL));
    int Number_Friends = 1 + rand() % N;

    for(int i = 1; i <= Number_Friends; i++){
        int x = rand() % N + 1;

            if(Friends[x] == true) --i;
        Friends[x] = true;
    }


    while(1){

        int final = false;
        for(int i = 1; i <= M; i++){
            if(R[i].type == 0)
               if ( Friends[R[i].x] ==false && !Friends[R[i].y] == false ){
                    final = true;
                    Friends[R[i].x] = true;
                    Number_Friends++;

               }
            if(R[i].type == 1)
                if(Friends[R[i].x] == false && Friends[R[i].y] == true){
                    final = true;
                    Friends[R[i].x] = true;
                    Number_Friends++;

                }
            if(R[i].type == 2)
                 if(Friends[R[i].x] == true && Friends[R[i].y] == false){
                    final = true;
                    Friends[R[i].x] = false;
                    Number_Friends--;

                }
            if(R[i].type == 1)
                if( Friends[R[i].x] == true && Friends[R[i].y] == true){
                    final = true;
                    Friends[R[i].x] = false;
                    Number_Friends--;
            }

        }
        if(final == false){
            fout << Number_Friends <<'\n';
            for(int i = 1; i <= N; i++)
                if(Friends[i] == true)
                    fout <<i <<'\n';
            break;
        }
    }
    return 0;
}