QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#93106#997. 2-SAT 问题Appleblue17#RE 0ms0kbC++14923b2023-03-31 10:59:502023-03-31 11:00:01

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-31 11:00:01]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2023-03-31 10:59:50]
  • Submitted

answer

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

int n,m;
vector <int> G[N];

int dfn[N],low[N],id;
stack <int> st;
bool vis[N];
int col[N],cid;

void tarjan(int u){
	dfn[u]=low[u]=++id;
	st.push(u);
	vis[u]=1;
	for(int v: G[u]){
		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]){
		cid++;
		while(1){
			int x=st.top(); st.pop();
			col[x]=cid;
			vis[x]=0;
			if(x==u) break;
		}
		
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		G[a+(b^1)*n].push_back(c+d*n);
		G[c+(d^1)*n].push_back(a+b*n);
	}
	for(int i=1;i<=n*2;i++)
		if(!dfn[i]) tarjan(i);
	for(int i=1;i<=n;i++)
		if(col[i]==col[i+n]) return cout<<"No",0;
	cout<<"Yes\n";
	for(int i=1;i<=n;i++)
		cout<<(col[i]>col[i+n])<<" ";
}

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

output:


result: