QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#547130 | #997. 2-SAT 问题 | Nityacke | WA | 31ms | 11376kb | C++20 | 846b | 2024-09-04 18:30:45 | 2024-09-04 18:30:46 |
Judging History
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.