poj 1814 2-Sat

这几天受尽了TLE,RE,都没有A过程序了。。。

今天多校,一道题也没有写出来,在别人看来的水题让我弄了好久就是tle,然后就是这几天一直陷入了2-SAT,感觉最近学东西好慢,好像是没怎么用心,白天和强神老是说话,晚上又是只顾玩了,感觉都没有上学期就晚上刷题的效率高的。上一场多校的解题报告还木有看,从暑假到学校来,我就将自己的任务记到有道笔记,然后今天看了一下,任务已经超过一页了,总是有增无减的,看来以后要更得加紧了,借钢牛的话,没有多少时间了!

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repf(i,n,m) for(int i=(n); i<=(m); i++)//正循环的
#define repd(i,n,m) for(int i=(n); i>=(m); i--) //负循环的
#define fab(a) ((a)>0?(a):(0-(a)))
#define ll long long
#define arc(a) ((a)*(a))
#define inf 10000000   //最大值的
#define exp 0.0000001     //浮点型的
#define N   17000  //记录开的数组
struct node
{
	int y,pre;
};
node a[40010];
int pre[40010];
int n,m,len;
int color[N];
queue<int>q;
int next[N];

void addpage(int s,int t)
{
	a[len].y=t;
	a[len].pre=pre[s];
	pre[s]=len++;
}

bool dfs(int x)
{
	if(color[x]==2) return false;
	if(color[x]==1) return true;
	next[len++]=x;
	color[x]=1;
	color[x^1]=2;
	for(int i=pre[x]; i!=-1; i=a[i].pre)
	{
		if(dfs(a[i].y)==false)
			return false;
	}
	return true;
}

bool find()
{
	rep(i,n)
	{
        if(color[i*2]!=0) continue;
		len=0;
		if(dfs(2*i)==false)
		{ 
			rep(j,len) color[next[j]]=color[next[j]^1]=0;
			if(dfs(2*i+1)==false)
				return false;
		}
	}
	return true;
}

int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		len=1;
		int x,y;
		memset(pre,-1,sizeof(pre));
		rep(i,m)
		{
			scanf("%d%d",&x,&y);
			--x,--y;
			addpage(x,y^1);
			addpage(y,x^1);//建图的
		}
        memset(color,0,sizeof(color));
		if(find()==false)
		{
			printf("NIE\n");
		}
		else
		{
            rep(i,n)
				if(color[i*2]==1)
					printf("%d\n",2*i+1);
				else printf("%d\n",2*i+2);
		}
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

淡定的小Y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值