QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#480490 | #997. 2-SAT 问题 | ucup-team1004# | RE | 0ms | 0kb | C++17 | 1.1kb | 2024-07-16 16:07:19 | 2024-07-16 16:07:19 |
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=1e5+10,M=5e5+10,V=N*2;
int n,m;
vector<int>to[N+N];
void add(int u,int v){
to[u].push_back(v);
}
int dft,sct,dfn[N],low[N],scc[N];
void tarjan(int u){
static int top,stk[N];
dfn[u]=low[u]=++dft,stk[++top]=u;
for(int v:to[u]){
if(!dfn[v])tarjan(v),low[u]=min(low[u],low[v]);
else if(!scc[v])low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
sct++;
do scc[stk[top]]=sct;while(stk[top--]^u);
}
}
int main(){
scanf("%d%d",&n,&m);
for(int u,x,v,y;m--;){
scanf("%d%d%d%d",&u,&x,&v,&y);
add(u+!x*n,v+y*n),add(v+!y*n,u+x*n);
}
for(int i=1;i<=n+n;i++)if(!dfn[i])tarjan(i);
for(int i=1;i<=n;i++){
if(scc[i]==scc[i+n])puts("No"),exit(0);
}
puts("Yes");
for(int i=1;i<=n;i++){
printf("%d%c",scc[i+n]<scc[i],"\n "[i<n]);
}
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
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...