看了十年才懂懂了十年才会会了十年才会写写了十年才写完写完了十年才能改对

#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:\nNothing special.\n\n",tt);
		else printf("Test case #%d:\nSomething wrong!\n\n",tt);
		for (i++; i < m; i++)scanf("%d%d", &from, &to);
	}
	return 0;
}

东大OJ 2SAT 异或的更多相关文章

  1. 杭电oj 2095 & 异或^符号在C/C++中的使用

    异或^符号,在平时的学习时可能遇到的不多,不过有时使用得当可以发挥意想不到的结果. 值得注意的是,异或运算是建立在二进制基础上的,所有运算过程都是按位异或(即相同为0,不同为1,也称模二加),得到最终 ...

  2. 中南oj 1216: 异或最大值 数据结构

    1216: 异或最大值 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 98  Solved: 29 [Submit][Status][Web Boar ...

  3. [Swust OJ 188]--异面空间(读懂题意很重要)

    题目链接:http://acm.swust.edu.cn/problem/188/ Time limit(ms): 1000 Memory limit(kb): 65535   江鸟来到了一个很奇怪的 ...

  4. 东大OJ-Max Area

    1034: Max Area 时间限制: 1 Sec  内存限制: 128 MB 提交: 40  解决: 6 [提交][状态][讨论版] 题目描述 又是这道题,请不要惊讶,也许你已经见过了,那就请你再 ...

  5. 异 形 卵 709 南阳oj

    http://acm.nyist.net/JudgeOnline/problem.php? pid=709 异 形 卵 时间限制:1000 ms  |  内存限制:65535 KB 难度: 描写叙述 ...

  6. Light oj 1251 - Forming the Council 【2-sat】【推断是否存在可行解 + 反向拓扑输出可行解】

    1251 - Forming the Council problem=1251" style="color:rgb(79,107,114)"> PDF (Engli ...

  7. TTTTTTTTTTTTTT POJ 3678 与或异或 2-SAT+强连通 模板题

    Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9129 Accepted: 3391 Descripti ...

  8. SWUST OJ 东6宿舍灵异事件(0322)

    东6宿舍灵异事件(0322) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 88 Accepted: 31   Descriptio ...

  9. [Swust OJ 322]--东6宿舍灵异事件(中缀表达式转化为后缀表达式的简单运用)

    题目链接:http://acm.swust.edu.cn/problem/322/ Time limit(ms): 1000 Memory limit(kb): 65535     Descripti ...

随机推荐

  1. linux基础-第十单元 系统的初始化和服务

    第十单元 系统的初始化和服务 Linux系统引导的顺序 Linux系统引导的顺序 BOIS的初始化和引导加载程序 什么是BIOS GRUB程序和grub.conf文件 什么是grub grub配置文件 ...

  2. Centos6.6下安装MySQL5.6

    1.先查看本机上已经安装的MySQL rpm –qa | grep -i mysql 如果存在信息说明已经安装MySQL 需要完全卸载以前的MySQL yum remove mysql mysql-s ...

  3. 使用Bootstrap v3.3.4注意细节box-sizing

    一.bootstrap样式 在Bootstrap v3.3.4中有下面一条重置样式: * { -webkit-box-sizing: border-box; -moz-box-sizing: bord ...

  4. Book LIst

    Go ahead. Linux APUE Linux Kernel Development 鸟哥的linux私房菜 基础篇 鸟哥的linux私房菜 服务器篇 Network Computer Netw ...

  5. 开启云时代,银狐H5游戏云通迅框架解决方案出炉!

    没有时间开发服务器? 不懂服务器开发? 还在为WEB SOCKET烦恼?还在为网络卡,负载承受能力小烦恼? 银狐H5游戏云通迅框架,集成通讯SDK和开放API,1天即可完成 它也是开放平台,提供游戏需 ...

  6. StringBuffer和StringBuilder的区别

    StringBuffer和StringBuilder的区别 StringBuffer与StringBuilder就不一样了,他们是字符串变量,是可改变的对象,每当我们用它们对字符串做操作时,实际上是在 ...

  7. BeanShell Assertion in Jmeter

    以下为几个beanshell assertion的栗子: if (ResponseCode != null && ResponseCode.equals ("200" ...

  8. poj1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12507   Accepted: 6070 Des ...

  9. Visual Studio 2015 Community连接到Mysql

    版权声明:本文为博主原创文章,未经博主允许不得转载. 本文首发于CSDN:http://blog.csdn.net/cxq2046/article/details/51108256 至今暂未授权其他任 ...

  10. Android手机浏览器访问本地网络相关问题

    为了测试开发的手机网站,常常需要使手机直接访问本地网络. 在这个过程中碰到几个问题,记下来供以后参考 1. 在本地主机运行apache后,使用localhost和127.0.0.1可以访问页面,但使用 ...