Cod sursa(job #352170)

Utilizator Addy.Adrian Draghici Addy. Data 30 septembrie 2009 17:04:00
Problema Balanta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <stdio.h>
#define DIM 1026

int A[DIM],B[DIM],H[DIM],L[DIM];
int n,m,i,j,k,x,rez,p,pozH,pozL;

int main() {
	
	FILE *f = fopen("balanta.in","r");
	FILE *g = fopen("balanta.out","w");
	
	fscanf(f,"%d%d",&n,&m);
	
	for (i=1; i<=n; i++) {
		H[i] = 1;
		L[i] = 1;
	}
	
	for (i=1; i<=m; i++) {
		fscanf(f,"%d",&k);
		for (j=1; j<=k; j++) {
			fscanf(f,"%d",&x);
			A[x] = 1;
		}
		for (j=1; j<=k; j++) {
			fscanf(f,"%d",&x);
			B[x] = 1;
		}
		fscanf(f,"%d",&rez);
		
		if (rez==0)
			for (j=1; j<=n; j++) {
				if (A[j])
					H[j] = L[j] = 0;
				if (B[j])
					H[j] = L[j] = 0;
			}
		
		if (rez==1) {
			for (j=1; j<=n; j++) {
				if (H[j] && !A[j])
					H[j] = 0;
				if (L[j] && !B[j])
					L[j] = 0;
			}
		}
		
		if (rez==2) {
			for (j=1; j<=n; j++) {
				if (H[j] && !B[j])
					H[j] = 0;
				if (L[j] && !A[j])
					L[j] = 0;
			}
		}
		
		for (j=1; j<=n; j++)
			A[j] = B[j] = 0;
	}
	
	for (i=1; i<=n; i++) {
		if (H[i]) {
			p++;
			pozH = i;
		}
		if (L[i]) {
			p++;
			pozL = i;
		}
	}
	
	if (p==1) {
		if (pozH)
			fprintf(g,"%d",pozH);
		if (pozL)
			fprintf(g,"%d",pozL);
	}
	else
		fprintf(g,"0");
	
	fclose(f);
	fclose(g);
	
	return 0;
}