BZOJ 1823: [JSOI2010]满汉全席

来源:互联网 发布:淘宝9.9元包邮专区 编辑:程序博客网 时间:2024/04/27 18:03

裸的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 longusing 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