Cod sursa(job #518499)

Utilizator ciprianfFarcasanu Alexandru Ciprian ciprianf Data 1 ianuarie 2011 14:51:40
Problema Party Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.75 kb
#include <stdio.h>
#include <vector>
using namespace std;
#define NMAX 210
#define FOR(i, v) for(vector<int>::iterator i = v.begin(); i != v.end(); ++i)
vector <int> G[NMAX], Gt[NMAX], V[NMAX];
int C[NMAX], R[NMAX], out[NMAX];
int viz[NMAX], st[NMAX];
int n, m, k;
int pun = 1, comp, pas;
inline int real(int x){
	if(x > 0) return x;
	return n-x;
}
inline void go_muchii(int x, int y){
	G[real(-x)].push_back(real(y));
	G[real(-y)].push_back(real(x));
	
	Gt[real(y)].push_back(real(-x));
	Gt[real(x)].push_back(real(-y));
}
void df(int x, vector<int> G[]){
	viz[x] = 1;
	if(!pas) C[x] = comp;
	FOR(i, G[x])
		if(!viz[*i])
			df(*i, G);
	out[x] = ++k;
	if(pun) st[++st[0]] = x;
}
void CTC(){
	for(int i = 1; i <= 2*n; ++i)
		if(!viz[i])
			df(i, G);
	pun = 0;
	memset(viz, 0, (2*n+3)*sizeof(viz[0]));
	for(int i = st[0]; i; --i)
		if(!viz[st[i]]){
			comp++;
			df(st[i], Gt);
		}
	
	for(int x = 1; x <= 2*n; ++x)
		FOR(i, G[x])
			if(C[x] != C[*i]) V[C[x]].push_back(C[*i]);
	
	memset(viz, 0, (2*n+3)*sizeof(viz[0]));
	k = 0;
	pas = 1;
	for(int x = 1; x <= comp; ++x)
		if(!viz[x])
			df(x, V);
}
void sat() {
	for(int x = 1; x <= n; ++x)
		if( out[C[x]] < out[C[real(-x)]]) R[C[x]] = 1;
		else R[C[real(-x)]] = 1;
	int c = 0;
	for(int i = 1; i <= n; ++i)
		if(R[C[i]]) c++;
	printf("%d\n", c);
	for(int i = 1; i <= n; ++i)
		if(R[C[i]]) printf("%d\n", i); 
}	
int main(){
	freopen("party.in", "r", stdin);
	freopen("party.out", "w", stdout);
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i){
		int x, y, c;
		scanf("%d%d%d", &x, &y, &c);
		if(c==0) ;
		else if(c == 1) y = -y;
		else if(c==2) x = -x;
		else {x = -x; y = -y;}
		go_muchii(x, y);
	}
	//CTC();
	//sat();
	printf("%d\n", 0);
	return 0;
}