BZOJ 1823: [JSOI2010]满汉全席

裸的2-SAT

被sb错误给卡了 

默认成字母后面只有一位数了  

调了半天  发现 读入就错了

集训一天 终于彻底傻逼了  呵呵呵呵呵……

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<iostream>
#define P 10000000
#define ll long long
using namespace std;
int head[2222],lst[44444],nxt[44444];
int dfn[2222],low[2222],bl[2222],vis[2222],st[2222];
int n,m,tot,cnt,top,scc,T;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int sc()
{
	int x;
	char c=getchar();
	while(c!='m'&&c!='h')c=getchar();
	if(c=='m')x=read()*2;
	else x=read()*2+1;
	return x;
}
void insert(int x,int y)
{
	lst[++tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}
void tarjan(int x)
{
	vis[x]=1;
	dfn[x]=low[x]=++cnt;
	st[++top]=x;
	for(int i=head[x]; i; i=nxt[i])
	{
		if(vis[lst[i]]) low[x]=min(low[x],dfn[lst[i]]);
		else if(!dfn[lst[i]])
		{
			tarjan(lst[i]);
			low[x]=min(low[x],low[lst[i]]);
		}
	}
	if(dfn[x]==low[x])
	{
		int k=0; scc++;
		while(k!=x)
		{
			k=st[top--];
			bl[k]=scc;
			vis[k]=0;
		}
	}
}
int main()
{
	cin >> T;
	while(T--)
	{
		memset(head,0,sizeof(head));
		memset(dfn,0,sizeof(dfn));
		int flag=0;tot=cnt=top=scc=0;
		scanf("%d%d",&n,&m);
		for(int i=1; i<=m; i++)
		{
			int x=sc(),y=sc();
			insert(y^1,x);
			insert(x^1,y);
		}
		for(int i=2; i<=n*2+1;i++)
		    if(!dfn[i])
		        tarjan(i);
		for(int i=1; i<=n; i++)
		    if(bl[i*2]==bl[i*2+1])
		    {puts("BAD");flag=1;break;}
		if(!flag) puts("GOOD");
	}
	return 0;
}
	


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值