QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#582547 | #997. 2-SAT 问题 | starryskymeow | WA | 60ms | 19940kb | C++20 | 2.8kb | 2024-09-22 16:48:56 | 2024-09-22 16:49:00 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...) 114514
#endif
using namespace std;
using LL = long long;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
const int INF = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const int N = 3e5 + 10;
struct TWO_SAT {
int siz;
std::vector<std::vector<int>> gra;
TWO_SAT(int size) : siz(size), gra(siz * 2 + 1) {}
// i -> x_i == 0, i + n -> x_i == 1
void add(int a, bool ta, int b, bool tb) {
gra[a + !ta * siz].push_back(b + tb * siz);
gra[b + !tb * siz].push_back(a + ta * siz);
}
std::vector<int> solve() {
std::vector<int> low(siz * 2 + 1), scc(siz * 2 + 1);
std::stack<int> sta;
int idx = 1, cnt = 0;
auto dfs = [&](int u, auto self) -> void {
low[u] = idx++;
int now = low[u];
sta.push(u);
for (auto v : gra[u]) {
if (!low[v])
self(v, self), low[u] = min(low[u], low[v]);
else if (!scc[v])
low[u] = min(low[u], low[v]);
}
if (low[sta.top()] <= now) {
cnt++;
while (sta.size() && low[sta.top()] >= now) {
auto t = sta.top();
sta.pop();
scc[t] = cnt;
}
}
};
for (int i = 1; i <= 2 * siz; i++) {
if (!low[i])
dfs(i, dfs);
}
std::vector<int> ans(siz + 1);
for (int i = 1; i <= siz; i++) {
if (scc[i] == scc[i + siz]) {
return std::vector<int>();
}
ans[i] = scc[i] > scc[i + siz];
}
return ans;
}
};
void solve() {
int n, m;
cin >> n >> m;
TWO_SAT ts(n);
for (int i = 0; i < m; i++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
ts.add(a, b, c, d);
}
auto res = ts.solve();
if (res.empty()) {
cout << "No" << '\n';
} else {
cout << "Yes" << '\n';
for (int i = 1; i <= n; i++) {
cout << res[i] << ' ';
}
cout << '\n';
}
}
signed main() {
#ifdef LOCAL
clock_t tttttttt = clock();
freopen("in.txt", "r", stdin);
#endif
#ifndef LOCAL
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
//*****************************************************************
int t = 1;
// cin >> t;
while (t--) solve();
//*****************************************************************
#ifdef LOCAL
cerr << "Time Used: " << fixed << setprecision(3) << (clock() - tttttttt) / (CLOCKS_PER_SEC / 1000.0) << " ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 32ms
memory: 12016kb
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:
Yes 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 0 0 ...
result:
ok Good plan
Test #2:
score: 0
Accepted
time: 39ms
memory: 9104kb
input:
17625 186889 17290 0 17616 1 8909 0 15829 0 9807 0 9920 1 14912 0 3052 1 14426 0 16910 1 8910 1 10153 1 5163 1 1118 1 2764 0 2787 1 2998 0 2344 1 17573 1 5693 1 9120 0 4529 1 9836 0 4832 0 4021 0 16206 1 1109 0 13286 1 12402 1 16982 0 6311 1 1218 1 147 0 5411 0 3958 1 1571 0 4848 1 16678 0 7433 1 31...
output:
Yes 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 0 1 0 0 0 1 0 0 1 0 1 1 1 1 0 0 0 1 1 0 1 1 1 1 0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 0 0 0 1 1 0 1 ...
result:
ok Good plan
Test #3:
score: 0
Accepted
time: 38ms
memory: 10156kb
input:
27276 180666 4575 1 13941 1 23689 1 276 1 8916 1 5504 1 10230 1 19907 1 15820 1 27258 0 18040 0 11405 0 23944 1 23049 1 12183 1 24927 0 26509 1 20881 0 14596 1 766 0 5071 1 10703 0 15926 1 25575 1 15486 1 35 0 11290 1 26937 0 3475 0 20672 1 10309 0 22343 1 22873 0 21025 0 14802 1 22377 0 7701 1 1185...
output:
Yes 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 1 0 1 1 0 0 1 0 1 1 1 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 1 ...
result:
ok Good plan
Test #4:
score: 0
Accepted
time: 38ms
memory: 11032kb
input:
70213 93094 53616 1 59247 1 16687 0 63568 0 10114 1 55521 1 58830 1 22082 0 46298 0 65072 0 2622 1 16071 0 66725 0 46161 1 4204 1 7255 0 39103 1 19710 1 33819 1 19406 0 24055 1 6494 1 45844 0 59888 0 63714 1 30868 0 12762 0 43441 0 59330 1 35278 0 2212 0 1284 0 45959 1 17786 1 17744 0 66761 1 54970 ...
output:
Yes 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 0 0 ...
result:
ok Good plan
Test #5:
score: 0
Accepted
time: 60ms
memory: 19940kb
input:
66484 178501 3057 1 32192 1 19941 0 37367 1 56292 0 54533 0 20407 1 27938 1 28653 1 37219 1 64377 0 63482 0 25218 0 12814 1 29736 0 34360 0 61150 0 38346 1 1116 0 56594 0 7410 1 58121 1 41370 0 36704 0 23807 1 60815 1 63396 0 55650 1 26564 1 5193 0 65150 1 27578 0 13215 0 5871 0 56406 1 63683 0 1321...
output:
No
result:
ok No Solution
Test #6:
score: 0
Accepted
time: 37ms
memory: 7336kb
input:
9650 160962 4804 1 3956 0 4557 0 7207 1 4157 1 7867 0 1045 0 5033 0 8623 0 5770 1 4090 1 3088 1 2846 0 8117 1 4827 1 474 0 2822 0 4035 1 2245 1 4894 0 5093 0 8553 1 9160 1 641 1 5302 1 7701 1 4246 0 718 0 2096 1 2709 1 4288 0 850 1 4262 0 1309 0 2713 1 286 0 7228 1 5945 1 7481 0 770 1 1617 1 4784 1 ...
output:
Yes 1 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 0 1 0 0 0 0 1 1 1 ...
result:
ok Good plan
Test #7:
score: 0
Accepted
time: 54ms
memory: 13012kb
input:
82878 170546 59669 0 52924 1 4674 1 27496 0 81463 1 82234 0 22606 0 30346 1 70787 1 16429 0 46983 0 80599 0 82208 0 51421 1 31035 0 74680 0 48903 1 55211 1 46935 1 76651 1 78465 0 18656 0 55607 1 13210 1 14749 1 25929 0 69893 1 23187 1 8840 0 5696 1 30898 1 14164 0 55439 1 68798 0 29324 1 6831 1 103...
output:
Yes 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0 1 1 1 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 ...
result:
ok Good plan
Test #8:
score: 0
Accepted
time: 26ms
memory: 11008kb
input:
22849 108511 22633 1 9868 1 1838 0 11979 0 16493 0 14662 1 4359 1 14080 1 1440 0 15825 1 1248 0 10522 0 5832 0 2369 0 16359 0 21931 1 4219 1 11059 1 17857 1 15021 0 527 0 12410 1 3606 1 11872 1 16771 1 695 0 21988 1 314 0 4674 1 18090 0 5861 1 21034 1 4147 1 7422 0 6607 1 9159 0 20501 1 16673 1 2152...
output:
No
result:
ok No Solution
Test #9:
score: 0
Accepted
time: 51ms
memory: 10284kb
input:
29366 167993 17695 1 9514 0 14236 0 9220 0 25155 0 5701 0 19605 0 26072 0 14919 1 9254 0 10628 0 11786 0 27612 1 25759 0 10256 1 7615 1 67 1 23478 0 17423 0 2671 0 22262 1 13960 0 13269 1 27431 0 13753 0 22134 0 22823 1 1997 1 24737 1 20863 1 6278 0 16541 0 4130 1 16469 0 29271 0 14263 1 21310 1 225...
output:
Yes 1 0 1 0 1 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 0 1 1 0 1 0 1 0 1 0 0 0 0 0 0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 0 0 ...
result:
ok Good plan
Test #10:
score: 0
Accepted
time: 31ms
memory: 6464kb
input:
1682 170188 916 0 1392 1 1635 1 1351 0 357 0 243 0 1225 0 254 1 266 0 1215 1 36 0 730 1 1544 0 526 0 316 1 1633 0 356 1 1231 0 940 0 1121 0 875 1 933 1 625 1 1241 1 1654 1 890 0 558 1 137 0 192 1 1131 0 1420 0 361 0 1507 1 739 1 1092 0 1090 0 1539 0 314 0 267 0 1152 1 1175 0 383 0 1585 1 1349 1 516 ...
output:
Yes 1 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 0 0 0 1 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 0 0 1 1 1 1 0 1 0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1 1 0 1 0 1 1 1 0 1 0 1 0 1 1 1 0 1 1 ...
result:
ok Good plan
Test #11:
score: 0
Accepted
time: 24ms
memory: 6092kb
input:
7196 105048 2859 0 287 1 689 0 3417 1 3339 1 5290 1 5024 1 386 0 1640 0 1248 1 3055 0 3501 1 6028 1 5555 0 5646 1 496 1 4043 0 2944 0 873 1 4251 1 4797 1 1369 0 198 1 6382 0 3985 1 4455 1 4165 1 7099 0 5910 1 6402 1 3784 0 5072 1 5727 0 5485 0 2384 0 1394 1 74 1 6712 0 7153 1 471 1 5020 1 3669 0 425...
output:
Yes 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 0 0 1 0 1 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 0 1 0 1 0 0 1 1 0 0 1 ...
result:
ok Good plan
Test #12:
score: 0
Accepted
time: 21ms
memory: 6980kb
input:
34766 55624 17816 1 18059 1 19359 1 7703 1 12707 1 8183 1 17814 0 4110 0 6119 0 12379 0 17510 0 34439 0 16709 0 22739 1 9555 1 3063 0 7258 0 21772 1 31924 1 4232 0 29692 0 29094 1 13653 1 16895 1 17462 1 27019 0 23572 1 18400 0 5748 0 1302 0 10769 1 15962 0 33973 1 14837 1 29160 0 12055 0 4429 1 114...
output:
Yes 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 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 1 0 0 1 0 0 1 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 ...
result:
ok Good plan
Test #13:
score: 0
Accepted
time: 24ms
memory: 6356kb
input:
5092 137430 2799 1 4966 1 542 1 1484 0 3411 0 1710 1 444 0 811 1 183 0 4372 0 3608 0 4255 0 729 1 2191 0 1917 1 1324 0 858 0 580 0 4222 0 4198 0 1169 0 4526 1 3296 0 1355 1 187 1 2818 0 4284 1 802 1 155 0 925 0 4226 0 1703 0 2990 0 3210 0 1106 0 3759 0 4922 1 1115 1 4740 1 4469 0 493 1 1264 1 1697 1...
output:
Yes 0 1 1 1 1 1 0 1 1 0 1 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 0 1 1 0 1 1 0 1 0 1 1 1 0 1 0 0 0 1 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 1 0 1 1 1 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 1 1 1 0 1 0 0 1 0 ...
result:
ok Good plan
Test #14:
score: 0
Accepted
time: 40ms
memory: 13440kb
input:
99252 104959 94974 1 15504 0 58094 0 8774 1 34526 1 90367 1 91897 1 17003 1 94791 0 20819 1 88290 0 1709 1 38261 1 55494 0 87494 0 59118 1 78954 0 664 0 94268 0 78725 0 26422 0 90161 1 65923 1 11045 0 37446 0 75065 1 59505 1 37830 1 88362 0 4670 1 82177 1 52868 1 72263 1 61602 0 80445 0 47243 0 6121...
output:
Yes 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 0 0 ...
result:
ok Good plan
Test #15:
score: -100
Wrong Answer
time: 38ms
memory: 9088kb
input:
40296 111028 37666 0 2212 1 11395 0 38653 1 11819 0 8871 0 13615 1 9629 0 16681 1 38246 0 17062 1 26243 0 34484 0 33388 0 21118 0 15952 0 9391 0 28190 1 38841 1 22721 0 17949 1 28537 1 23998 0 2167 0 18529 0 38047 0 37808 1 28816 0 35241 1 22402 0 22784 0 2297 1 25196 1 8670 0 36433 1 15279 1 1130 0...
output:
No
result:
wrong answer You didn't find a solution but jury did.