QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#93386#997. 2-SAT 问题chenshi#WA 52ms23528kbC++1.3kb2023-03-31 18:46:582023-03-31 18:46:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-31 18:46:59]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:23528kb
  • [2023-03-31 18:46:58]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
const int o=1e6+10;
int n,m,h[o],cnt,dfn[o],low[o],st[o],tp,scc[o],sccn,H[o],Cnt,d[o],topo[o];bool vis[o];queue<int> q;
struct Edge{int v,p;}e[o],E[o];
inline void ad(int U,int V){e[++cnt].v=V;e[cnt].p=h[U];h[U]=cnt;}
inline void Ad(int U,int V){++d[E[++Cnt].v=V];E[Cnt].p=H[U];H[U]=Cnt;}
void tarjan(int nw){
	dfn[nw]=low[nw]=++cnt;vis[st[++tp]=nw]=1;
	for(int i=h[nw];i;i=e[i].p)
		if(!dfn[e[i].v]) tarjan(e[i].v),low[nw]=min(low[nw],low[e[i].v]);
		else if(vis[e[i].v]) low[nw]=min(low[nw],dfn[e[i].v]);
	if(dfn[nw]==low[nw]) for(++sccn;st[tp+1]^nw;vis[st[tp--]]=0) scc[st[tp]]=sccn;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int a,b,c,d;m--;) scanf("%d%d%d%d",&a,&b,&c,&d),ad(a+(!b)*n,c+d*n),ad(c+(!d)*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(scc[i]==scc[i+n]){printf("No");return 0;}
	for(int i=1;i<=n*2;++i) for(int j=h[i];j;j=e[j].p) if(scc[i]^scc[e[j].v]) Ad(scc[i],scc[e[j].v]);
	for(int i=1;i<=sccn;++i) if(!d[i]) q.push(i);
	for(cnt=0;!q.empty();topo[q.front()]=++cnt,q.pop())
		for(int i=H[q.front()];i;i=E[i].p) if(!--d[E[i].v]) q.push(E[i].v);
	printf("Yes\n");
	for(int i=1;i<=n;++i) printf("%d ",topo[scc[i]]>topo[scc[i+n]]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 52ms
memory: 23528kb

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:

Yes
0 0 0 1 0 1 1 1 0 1 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 1 1 1 0 1 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1 1 1 1 0 0 0 0 1 0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 1 0 0 ...

result:

wrong answer Your plan didn't satisfy condition #1.(i = 14615, a = 0, j = 14903, b = 1)