东大OJ 2SAT 异或

看了十年才懂懂了十年才会会了十年才会写写了十年才写完写完了十年才能改对
#include<stdio.h>
#include<string.h>
struct res{
	int steps;
	int father;
};
int a[50001];
res findfather(int me){
	res r;
	r.steps = 0;
	while (a[me] != -1){ me = a[me]; r.steps++; }
	r.father = me;
	return r;
}
int main(){
	freopen("in.txt", "r", stdin);
	int n, m;
	int t;
	scanf("%d", &t);
	int tt;
	for (tt = 1; tt <= t; tt++){
		scanf("%d%d", &n, &m);
		memset(a, -1, sizeof(a));
		int i;
		int from, to;
		for (i = 0; i < m; i++){
			scanf("%d%d", &from, &to);
			res rf = findfather(from);
			res rt = findfather(to);
			if (rf.father == rt.father)
			{
				if((rf.steps + rt.steps) % 2 == 0)
					break; 
				else continue;
			}
			if (rt.steps%2==0)a[rt.father] = from;
			else if (rf.steps % 2 == 0)a[rf.father] = to;
			else a[rf.father] = a[to];
		}
		if (i == m)printf("Test case #%d:
Nothing special.

",tt);
		else printf("Test case #%d:
Something wrong!

",tt);
		for (i++; i < m; i++)scanf("%d%d", &from, &to);
	}
	return 0;
}

原文地址:https://www.cnblogs.com/weiyinfu/p/5013897.html