QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#481609 | #997. 2-SAT 问题 | Sktn0089# | RE | 0ms | 0kb | C++14 | 1.1kb | 2024-07-17 11:31:27 | 2024-07-17 11:31:27 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pir pair <ll, ll>
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
const ll maxn = 1e5 + 10;
ll n, m, a, b, c, d;
ll scc[maxn], cnt, dfn[maxn], low[maxn], ti, stk[maxn], top, vis[maxn];
vector <ll> to[maxn];
void tarjan(ll u) {
dfn[u] = low[u] = ++ti, vis[stk[++top] = u] = 1;
for(ll v: to[u])
if(dfn[v]) {
if(vis[v]) low[u] = min(low[u], dfn[v]);
} else {
tarjan(v); low[u] = min(low[u], low[v]);
}
if(dfn[u] == low[u]) {
++cnt, stk[top + 1] = 0;
while(stk[top + 1] ^ u) {
ll x = stk[top--]; vis[x] = 0;
scc[x] = cnt;
}
}
}
int main(){
scanf("%lld%lld", &n, &m);
for(ll i = 1; i <= m; i++) {
scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
to[a + (b ^ 1) * n].pb(c + d * n);
to[c + (d ^ 1) * n].pb(a + b * n);
}
for(ll i = 1; i <= 2 * n; i++)
if(!dfn[i]) tarjan(i);
for(ll i = 1; i <= n; i++)
if(scc[i] == scc[i + n]) { puts("No"); return 0; }
puts("Yes");
for(ll i = 1; i <= n; i++)
printf("%lld ", (ll) (scc[i] > scc[i + n]));
return 0;
}
详细
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...