Cod sursa(job #485090)

Utilizator indestructiblecont de teste indestructible Data 16 septembrie 2010 23:13:17
Problema Andrei Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <stdio.h>
#include <vector>
#include <time.h>
#include <string.h>
#define NMAX 100005
#define LMAX 200005
#define NR 3
using namespace std;
int n,m,B[NMAX];
struct muchie
{
	int a,b,c;
};
muchie A[LMAX];
void read()
{
	scanf("%d%d",&n,&m);
	int i;
	for (i=1; i<=m; i++)
		scanf("%d%d%d",&A[i].a,&A[i].b,&A[i].c);
}
void solve()
{
	srand(time(0));
	int i,found=0;
	for (i=1; i<=n; i++)
		B[i]=rand()%2;
	while (!found)
	{
		found=1;
		for (i=1; i<=m; i++)
		{
			if (A[i].c==0 && B[A[i].a]==0 && B[A[i].b]==0)
			{
				found=0;
				break ;
			}
			if (A[i].c==1 && B[A[i].a]==1 && B[A[i].b]==1)
			{
				found=0;
				break ;
			}
			if (A[i].c==2 && B[A[i].a]+B[A[i].b]==1)
			{
				found=0;
				break ;
			}
		}
		if (found) 
			break ;
		if (rand()%2==0)
			B[A[i].a]^=1;
		else
			B[A[i].b]^=1;
	}
}
void show()
{
	int i;
	for (i=1; i<=n; i++)
		printf("%d ",B[i]);
	printf("\n");
}
int main()
{
	freopen("andrei.in","r",stdin);
	freopen("andrei.out","w",stdout);
	read();
	solve();
	show();
	return 0;
}