【无聊放个模板系列】POJ 3678 2-SAT
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
#define Maxn 1010
#define Maxm 1000010 char s[];
int n,m; struct node
{
int x,y,next;
}t[*Maxm];int len;
int first[*Maxn]; void ins(int x,int y)
{
t[++len].x=x;t[len].y=y;
t[len].next=first[x];first[x]=len;
} bool mark[*Maxn];
int S[*Maxn]; bool dfs(int x)
{
if(mark[x^]) return ;
if(mark[x]) return ;
S[++S[]]=x;mark[x]=;
for(int i=first[x];i;i=t[i].next)
{
int y=t[i].y;
if(!dfs(y)) return ;
}
return ;
} bool tsat()
{
for(int i=;i<n;i++)
{
if(!mark[*i]&&!mark[*i+])
{
S[]=;
if(!dfs(*i))
{
while(S[]) mark[S[S[]--]]=;
if(!dfs(*i+)) return ;
}
}
}
return ;
} int main()
{
scanf("%d%d",&n,&m);
len=;
memset(first,,sizeof(first));
for(int i=;i<=m;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
scanf("%s",s);
if(s[]=='A')
{
if(z==)
{
ins(*x,*y);ins(*x,*y+);
ins(*y,*x);ins(*y,*x+);
}
else
{
ins(*x+,*y);
ins(*y+,*x);
}
}
else if(s[]=='O')
{
if(z==)
{
ins(*x,*y+);
ins(*y,*x+);
}
else
{
ins(*x+,*y);ins(*x+,*y+);
ins(*y+,*x);ins(*y+,*x+);
}
}
else if(s[]=='X')
{
if(z==)
{
ins(*x,*y+);ins(*x+,*y);
ins(*y,*x+);ins(*y+,*x);
}
else
{
ins(*x,*y);ins(*x+,*y+);
ins(*y,*x);ins(*y+,*x+);
}
}
}
if(tsat()) printf("YES\n");
else printf("NO\n");
return ;
}
2-SAT
2016-11-17 22:00:10
【无聊放个模板系列】POJ 3678 2-SAT的更多相关文章
- 【无聊放个模板系列】POJ 1274 (匈牙利)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】BZOJ 3172 (AC自动机)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】POJ2752 EXKMP
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】HDU 3506 (四边形不等式优化DP-经典石子合并问题[环形])
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】BZOJ 1597 斜率优化
STL 双向队列DEQUE版本 #include<cstdio> #include<cstdlib> #include<cstring> #include<i ...
- 【无聊放个模板系列】HDU 1269 (SCC)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】HDU 1358 KMP
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】HDU 3068 MANACHER
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- HDU 3062 && HDU 1824 && POJ 3678 && BZOJ 1997 2-SAT
一条边<u,v>表示u选那么v一定被选. #include <iostream> #include <cstring> #include <cstdio> ...
随机推荐
- 使用edgesForExtendedLayout遇到的麻烦
今天在写一个多界面之间来回返回的工程时,遇到的问题,建了两个类:FirstViewController 和 ButtonViewController. 由 FirstViewController 进入 ...
- 关于web请求中 获取真实IP
HttpRequest request = HttpContext.Current.Request; if (!string.IsNullOrEmpty(request.ServerVariables ...
- HDU 2340 Obfuscation(dp)
题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...
- JSON的使用
最近在项目中大量的使用了JSON, 发现JSON和XML的功能相近,都是一种数据传输格式.只是与XML相比JSON显得更加轻量级,使用也更加容易. JSON依赖的第三方jar包: commons-be ...
- DevExpress gridView 小结(一)
一:第一列显示行号 CustomDrawRowIndicator this.gridViewDevice.IndicatorWidth = 40; this.gridViewDevice.Custo ...
- wap手机端解决返回上一页,js
<input id="hd_referrer" type="hidden" /> <a href="j ...
- sql server 查看创建视图的sql语句
--sp_helptext v_viewnamesp_helptext port_dept--效果
- RTC搭建android下三层应用程序访问服务器MsSql-服务器端
前几天通过Ro搭建webservice,然后在android下调用,虽然已近成功,但是返回的数据库里的中文有乱码一直未得到解决!rtc6.23版本,已经支持xe5,也支持fmx的android下开发, ...
- 数据可视化(三)- Seaborn简易入门
本文内容来源:https://www.dataquest.io/mission/133/creating-compelling-visualizations 本文数据来源:http://www.cdc ...
- 【转】C#路径/文件/目录/I/O常见操作汇总
文件操作是程序中非常基础和重要的内容,而路径.文件.目录以及I/O都是在进行文件操作时的常见主题,这里想把这些常见的问题作个总结,对于每个问题,尽量提供一些解决方案,即使没有你想要的答案,也希望能提供 ...