首页 技术 正文
技术 2022年11月18日
0 收藏 618 点赞 3,355 浏览 1391 个字

思路:裸的2-SAT。

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Maxn 2010
#define Maxm 100010
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 0x7fffffff
#define Mod 1000000007
using namespace std;
int dfn[Maxn],low[Maxn],id[Maxn],Stack[Maxn],lab,num,e,top,vi[Maxn],n,m;
vector<int> head[Maxn];
void init()
{
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
lab=num=top=;
memset(vi,,sizeof(vi));
memset(id,,sizeof(id));
for(int i=;i<=*n;i++)
head[i].clear();
}
void Tarjan(int u)
{
int i,v,sz;
dfn[u]=low[u]=++lab;
Stack[top++]=u;
vi[u]=;
sz=head[u].size();
for(i=;i<sz;i++){
v=head[u][i];
if(!dfn[v]){
Tarjan(v);
low[u]=min(low[v],low[u]);
}
if(vi[v])
low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u]){
++num;
do{
i=Stack[--top];
id[i]=num;
vi[i]=;
}while(i!=u);
}
return ;
}
int main()
{
int i,j,a,b,c,d;
while(scanf("%d",&n)!=EOF){
init();
scanf("%d",&m);
for(i=;i<=m;i++){
scanf("%d%d%d%d",&a,&b,&c,&d);
a++;
b++;
if(c==&&d==)
head[a].push_back(b+n),head[b].push_back(a+n);
if(c==&&d==)
head[a].push_back(b),head[b+n].push_back(a+n);
if(c==&&d==)
head[a+n].push_back(b+n),head[b].push_back(a);
if(c==&&d==)
head[a+n].push_back(b),head[b+n].push_back(a);
}
for(i=;i<=*n;i++){
if(!dfn[i])
Tarjan(i);
}
for(i=;i<=n;i++)
if(id[i]==id[i+n])
break;
if(i<=n)
printf("NO\n");
else
printf("YES\n");
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860