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

#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. 使用bakefile编译C工程代码

    前言 最近有个想法,想把ineedle整体架构从头自己编写代码来实现一下,来加深对iNeedle系统的理解,同时加强Linux + C相关知识.由于iNeedle系统的庞大,只能是先把框架搭起来,根据 ...

  2. ES6 Set/WeakSet

    ES6里加入了一个新数据解构Set,和Java的Set一样,它里面不存放重复的元素.Set实现为一个类,使用时需要先new. var s1 = new Set() s1.add(1) s1.add(2 ...

  3. js中的遍历foreach,$.each(),$().each()

    <!DOCTYPE html> <html> <head> <meta charset='UTF-8'> <title></title ...

  4. ixgbe rx_missed_errors

    https://communities.intel.com/thread/54600?start=0&tstart=0 I am acquiring 800Mb/sec+ multicast ...

  5. 报表开发工具中开放的部分图表js接口列表

    1.. 描述 报表开发工具FineReport 8.0版本中开放了部分图表js接口,在具体应用的过程中很多人都不知道这些接口到底有什么作用,该怎么应用,所以根据我自己的应用在下面归纳了这些新开放js接 ...

  6. [转]Backbone.js简单入门范例

    本文转自:http://dmyz.org/archives/598 11年刚开始用前端MVC框架时写过一篇文章,当时Knockout和Backbone都在用,但之后的项目全是在用Backbone,主要 ...

  7. cuda fft 计算

    #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h&g ...

  8. 怎样实现ZBrush中的智能对称

    ZBrush软件智能化和人性化的工作流程让用户在创作中提高工作效率,体验创作乐趣,说起智能化不得不提的就是ZBrush给我们提供的智能对称功能,所谓的智能对称就是当您在编辑其中一半的物体模型时,执行相 ...

  9. Remove Duplicates From Sorted Array

    Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...

  10. 第二届中国移动互联网测试大会PPT

    第二届中国移动互联网测试大会PPT下载_360云盘 (提取密码:7799) 第二届中国移动互联网测试大会PPT下载_百度云盘 (提取密码: ws8m) 第二届中国移动互联网测试大会PPT下载_Goog ...