QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#463422 | #997. 2-SAT 问题 | crazy_sea# | RE | 0ms | 0kb | C++14 | 902b | 2024-07-04 20:17:33 | 2024-07-04 20:17:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
struct edge{
int next,to;
}e[N<<1];
int first[N],len,n,m,cnt,tot,col[N],dfn[N],low[N],t[N];
void add(int a,int b)
{
e[++len]=edge{first[a],b};
first[a]=len;
}
void dfs(int x)
{
dfn[x]=low[x]=++cnt,t[++len]=x;
for(int i=first[x],y;i;i=e[i].next)
if(!dfn[y=e[i].to]) dfs(y),low[x]=min(low[x],low[y]);
else if(!col[y]) low[x]=min(low[x],low[y]);
if(dfn[x]==low[x])
{
col[x]=++tot;
while(t[len]==x) col[t[len--]]=tot;
len--;
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1,a,b,c,d;i<=m;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
add(a+(b^1)*n,c+d*n);
add(c+(d^1)*n,a+b*n);
}
len=0;
for(int i=1;i<=n*2;i++) if(!dfn[i]) dfs(i);
for(int i=1;i<=n;i++) if(col[i]==col[i+n]) return puts("No"),0;
puts("Yes");
for(int i=1;i<=n;i++) printf("%d%c",(col[i]<col[i+n])," \n"[i==n]);
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
86354 86418 14615 0 14903 1 13605 0 4458 0 15604 0 77112 0 52311 1 64996 0 22711 1 74245 1 39042 1 57372 1 2994 1 84183 1 80574 0 58791 1 27780 1 9336 1 61809 0 7216 0 71113 0 42287 1 20073 0 72448 0 73840 0 77048 0 28955 0 4165 0 16322 1 14075 1 43512 0 58600 1 45219 0 53858 0 14919 0 22576 0 16594...