东大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:\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 异或的更多相关文章
- 杭电oj 2095 & 异或^符号在C/C++中的使用
异或^符号,在平时的学习时可能遇到的不多,不过有时使用得当可以发挥意想不到的结果. 值得注意的是,异或运算是建立在二进制基础上的,所有运算过程都是按位异或(即相同为0,不同为1,也称模二加),得到最终 ...
- 中南oj 1216: 异或最大值 数据结构
1216: 异或最大值 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 98 Solved: 29 [Submit][Status][Web Boar ...
- [Swust OJ 188]--异面空间(读懂题意很重要)
题目链接:http://acm.swust.edu.cn/problem/188/ Time limit(ms): 1000 Memory limit(kb): 65535 江鸟来到了一个很奇怪的 ...
- 东大OJ-Max Area
1034: Max Area 时间限制: 1 Sec 内存限制: 128 MB 提交: 40 解决: 6 [提交][状态][讨论版] 题目描述 又是这道题,请不要惊讶,也许你已经见过了,那就请你再 ...
- 异 形 卵 709 南阳oj
http://acm.nyist.net/JudgeOnline/problem.php? pid=709 异 形 卵 时间限制:1000 ms | 内存限制:65535 KB 难度: 描写叙述 ...
- Light oj 1251 - Forming the Council 【2-sat】【推断是否存在可行解 + 反向拓扑输出可行解】
1251 - Forming the Council problem=1251" style="color:rgb(79,107,114)"> PDF (Engli ...
- TTTTTTTTTTTTTT POJ 3678 与或异或 2-SAT+强连通 模板题
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9129 Accepted: 3391 Descripti ...
- SWUST OJ 东6宿舍灵异事件(0322)
东6宿舍灵异事件(0322) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 88 Accepted: 31 Descriptio ...
- [Swust OJ 322]--东6宿舍灵异事件(中缀表达式转化为后缀表达式的简单运用)
题目链接:http://acm.swust.edu.cn/problem/322/ Time limit(ms): 1000 Memory limit(kb): 65535 Descripti ...
随机推荐
- android PopupWindow使用实例
注:点空白或菜单外隐藏popupwindow菜单: 但是,若点击有点击事件的组件则要再写代码手动隐藏: @Override public boolean onTouchEvent(MotionEven ...
- 让CKEditor支持FLV视频播放
平时都是做C/S开发,最近需要维护一个协会门户网站. 文章编辑使用CKEditor 3.3.2 + ckfinder 2.0的方案.可是这种方案居然不支持FLV视频播放,度娘说以前的老版本是支持的,这 ...
- .Net程序员之Python基础教程学习----判断条件与循环[Fourth Day]
今天学习Python的判断条件与循环操作. 一. 布尔变量: 在学习判断条件之前必须的了解bool变量,在Python中bool变量与C语言比较类似,与.net差别比较大,其中下面集中情况需要 ...
- unix automake 使用,快速生成你的Makefile
使用automake快速生成编译的Makefile 1,确保自己装有的软件automake autoconf 2, 1)执行autoscan 并将生成的configure.scan重命名为config ...
- Java Web开发之分页(ajax)
1.需要用到的jar包.js文件 JSONArray().fromObject()需要的jar包: (1)commons-beanutils-1.8.3.jar (2)commons-collecti ...
- poj3635Full Tank?[分层图最短路]
Full Tank? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7248 Accepted: 2338 Descri ...
- C#添加测量运行时间
使用范围 使用模块化开发,每个模块都有初始化功能,初始化功能可能包括:加载配置表,初始化事件,初始化设置 那么如果想测量每个模块的Init时间呢?Net框架已经提供了测量运行的方法 System.Di ...
- [No000020]背单词提不起兴趣怎么办?
- java 22 - 11 多线程之模拟电影院售票口售票
使用多线程实现的第二种方式: 首先创建自定义类 public class SellTicket implements Runnable { // 定义100张票 private int ticket ...
- git删除分支|查看分支动态
git不能在当前分支下删除你当前所在的分支,比如你要删除new分支,而现在正在处于new分支下,则执行git branch -d new的时候会报错 error: Cannot delete bran ...