zoukankan      html  css  js  c++  java
  • 东大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;
    }

  • 相关阅读:
    继承 接口 多态
    组合(补充)和 继承
    面向对象初级
    模块和包
    time,random,os,sys,序列化模块
    inline详解
    C++静态数据成员与静态成员函数
    OpenCV Mat数据类型及位数总结(转载)
    拼搏奋斗类
    c++虚函数实现机制(转)
  • 原文地址:https://www.cnblogs.com/weiyinfu/p/5013897.html
Copyright © 2011-2022 走看看