Pagini recente » Cod sursa (job #1665314) | Cod sursa (job #1863891) | Cod sursa (job #1011130) | Cod sursa (job #1255492) | Cod sursa (job #844278)
Cod sursa(job #844278)
#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;
}