QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547130#997. 2-SAT 问题NityackeWA 31ms11376kbC++20846b2024-09-04 18:30:452024-09-04 18:30:46

Judging History

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

  • [2024-09-04 18:30:46]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:11376kb
  • [2024-09-04 18:30:45]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=2e5+5;
vector<int>G[N];
int n,m,st[N],top;
bool vis[N];
inline void add(int u,int v){G[u].pb(v^1),G[v].pb(u^1);}
inline bool dfs(int x){
	if(vis[x^1]) return 0;
	if(vis[x]) return 1;
	vis[x]=1,st[++top]=x;
	for(auto v:G[x])
		if(!dfs(v)) return 0;
	return 1;
}
inline bool check(){
	for(int i=0;i<n*2;i+=2)
		if(!vis[i]&&!vis[i^1]){
			int tmp=top;
			if(!dfs(i)){
				while(top>tmp) vis[st[top--]]=0;
				if(!dfs(i^1)) return 0;
			}
		}
	return 1;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1,x,a,y,b;i<=m;++i)
		cin>>x>>a>>y>>b,add(((x-1)<<1)|(1-a),((y-1)<<1)|(1-b));
	if(!check()) return puts("IMPOSSIBLE"),0;
	cout<<"POSSIBLE\n";
	for(int i=1;i<2*n;i+=2) cout<<vis[i]<<" ";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 31ms
memory: 11376kb

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:

POSSIBLE
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

wrong answer You didn't find a solution but jury did.