QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#93414 | #997. 2-SAT 问题 | doctorZ_# | RE | 0ms | 0kb | C++14 | 1.2kb | 2023-03-31 20:10:30 | 2023-03-31 20:10:34 |
Judging History
answer
#include<cstdio>
#include<algorithm>
using namespace std;
void read(int &res)
{
res=0;char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while('0'<=ch&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
}
const int N=1e5+100,M=2e6+100;
int n,m;
int st[N+10],tot;
struct edge
{
int to,last;
}e[M<<1|1];
void add(int a,int b)
{
// printf("edge %d %d\n",a,b);
e[++tot].to=b;
e[tot].last=st[a];
st[a]=tot;
}
bool vis[N+10];
int dfn[N+10],low[N+10],co[N+10],stack[N+10],top;
void tarjan(int u)
{
dfn[u]=low[u]=++dfn[0],stack[++top]=u,vis[u]=true;
for(int i=st[u],v;i!=0;i=e[i].last)
{
v=e[i].to;
if(!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
else
if(vis[v])
low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u])
{
co[0]++,stack[top+1]=0;
while(stack[top+1]!=u) co[stack[top]]=co[0],vis[stack[top]]=false,top--;
}
}
int main()
{
read(n),read(m);
for(int i=1,a,b,c,d;i<=m;i++)
{
read(a),read(b),read(c),read(d);
add(a+(b^1)*n,c+d*n);
add(c+(d^1)*n,a+b*n);
}
for(int i=1;i<=n*2;i++)
if(!dfn[i])
tarjan(i);
for(int i=1;i<=n;i++)
if(co[i]==co[n+i])
{
puts("No");
return 0;
}
puts("Yes");
for(int i=1;i<=n;i++) printf("%d ",co[n+i]<co[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
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...