Pagini recente » Cod sursa (job #1538548) | Cod sursa (job #1623124) | Cod sursa (job #1497164) | Cod sursa (job #1190675) | Cod sursa (job #844302)
Cod sursa(job #844302)
#include<fstream>
#include<stdlib.h>
#include<time.h>
using namespace std;
ifstream fin("party.in");
ofstream fout("party.out");
#define NMAFirst_friends 102
#define MMAFirst_friends 1002
int N, M;
bool Friends[NMAFirst_friends];
struct Relation {int type, First_friends, y;};
Relation R[MMAFirst_friends];
void read(){
fin >> N >>M;
for(int i = 1; i <= M; i++)
R[i].First_friends >> 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 == 1) return !a || !b;
}
int main(){
read();
srand(time(NULL));
int Number_Friends = 1 + rand() % N;
for(int i = 1; i <= Number_Friends; i++){
int First_friends = rand() % N + 1;
Friends[First_friends] = true;
}
for(int i = 1; i <= M; i++)
if(!verifica(i, Friends[R[i].First_friends] , Friends[R[i].y])){
int r = rand() % 2;
if(r) Friends[R[i].First_friends] = !Friends[R[i].First_friends];
else Friends[R[i].y] = !Friends[R[i].y];
i = 0;
}
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;
}