QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#792950#997. 2-SAT 问题cppcppcpp3RE 0ms0kbC++141.3kb2024-11-29 15:17:082024-11-29 15:17:09

Judging History

你现在查看的是最新测评结果

  • [2024-11-29 15:17:09]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-29 15:17:08]
  • 提交

answer

#include<bits/stdc++.h>
#define eb emplace_back
using namespace std;
const int N=1e5+5;

static char buf[1000000],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
inline int wrd(){int x=0,f=1;char c=getchar();while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+c-48;c=getchar();}return x*f;}
inline void write(int x){static char buf[20];static int len=-1;if(x<0)putchar('-'),x=-x;do buf[++len]=x%10,x/=10;while(x);while(len>=0)putchar(buf[len--]+48);}

int n,m;
int id(int x,int y){return x+n*y;}

vector<int> e[N];
int low[N],dfn[N],tot,st[N],tp,bl[N],sc;
bool vs[N];

void dfs(int u){
	low[u]=dfn[u]=++tot,st[++tp]=u,vs[u]=1;
	for(int v:e[u]){
		if(!dfn[v]) dfs(v),low[u]=min(low[u],low[v]);
		else if(vs[v]) low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u]){
		++sc;
		for(int x=0;x^u;--tp) x=st[tp],bl[x]=sc,vs[x]=0;
	}
}

signed main(){
	n=wrd(),m=wrd();
	for(int i=1;i<=m;++i){
		int u=wrd(),a=wrd(),v=wrd(),b=wrd();
		e[id(u,a^1)].eb(id(v,b)),
		e[id(v,b^1)].eb(id(u,a));
	}
	for(int i=1;i<=(n<<1);++i) if(!dfn[i]) dfs(i);
	for(int i=1;i<=n;++i) if(bl[i]==bl[n+i]) puts("No"),exit(0);
	puts("Yes");
	for(int i=1;i<=n;++i) putchar(bl[i]<bl[n+i]?'0':'1'),putchar(' ');
	return 0;
}

详细

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...

output:


result: