QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#480804 | #997. 2-SAT 问题 | ningago# | WA | 28ms | 31264kb | C++14 | 4.0kb | 2024-07-16 18:58:26 | 2024-07-16 18:58:27 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cctype>
#include <queue>
#include <cmath>
#include <map>
#include <vector>
#include <set>
namespace uvu
{
#define LOCAL _______________DONT_DEFINE_NE___________________
#define ll long long
#define inf 0x3f3f3f3f
// #define int long long
// #define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
return getchar();
#else
if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}
void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct flusher { ~flusher(){ Flush(); }}iamflusher;
void putc(char c)
{
#ifdef LOCAL
putchar(c);
#else
*oS++ = c;
if(oS == oT) Flush();
#endif
}
template <typename T = int> T read()
{
T x = 0, f = 1; char c = getc();
for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
for(; isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
return x * f;
}
template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
top = 0;
if(x < 0) putc('-'), x = -x;
if(!x) sta[top = 1] = 0;
for(; x; x /= 10) sta[++top] = x % 10;
for(; top; ) putc(sta[top--] ^ 48);
if(c) putc(c);
}
int readstr(char *s, int base)
{
int idx = base - 1; char c = getc();
for(; !(isdigit(c) || isalpha(c) || c == '.' || c == '_'); c = getc());
for(; isdigit(c) || isalpha(c) || c == '.' || c == '_' ; c = getc()) s[++idx] = c;
return idx - base + 1;
}
void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
for(; *s; s++)
{
if(*s != '%') { putc(*s); continue; }
s++; if(*s == 'd') print(x, 0);
else if(*s == 'c') putc(x);
printf(s + 1, rest ...);
return;
}
}
template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = sm(x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }
#define N 1000010
int n, m;
int h[N], e[N], ne[N], idx = -1;
void add_edge(int x, int y) { ne[++idx] = h[x], h[x] = idx, e[idx] = y; }
void add(int x, int y) { add_edge(x, y), add_edge(y, x); }
int dfn[N], low[N], sta[N], top;
bool insta[N]; int scc[N], sc;
void tarjan(int k)
{
dfn[k] = low[k] = ++dfn[0];
insta[sta[++top] = k] = 1;
for(int i = h[k]; ~i; i = ne[i])
{
int nx = e[i];
if(!dfn[nx]) { tarjan(nx); ckmin(low[k], low[nx]); }
else if(insta[nx]) ckmin(low[k], dfn[nx]);
}
if(dfn[k] == low[k]) { ++sc; while(1) { int v = sta[top--]; insta[v] = 0; scc[v] = sc; if(v == k) break; } }
}
void solve()
{
memset(h, idx = -1, sizeof(h));
n = read(), m = read();
for(int i = 1, a, x, b, y; i <= m; i++)
{
a = read(), x = read(), b = read(), y = read();
add_edge(a + (x ^ 1) * n, b + y * n);
add_edge(b + (y ^ 1) * n, a + x * n);
}
for(int i = 1; i <= n + n; i++) if(!dfn[i]) tarjan(i);
for(int i = 1; i <= n; i++) if(dfn[i] == dfn[i + n]) { printf("No\n"); return; }
printf("Yes\n");
for(int i = 1; i <= n; i++) printf("%d ", scc[i] > scc[i + n]);
putc('\n');
}
void init()
{
}
char _ED_;
void mian()
{
debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
init();
for(int T = 1; T; T--, solve());
}
#ifdef int
#undef int
#endif
}
int main()
{
// freopen("tmp.in", "r", stdin);
// freopen("tmp.out", "w", stdout);
uvu::mian(); return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 27524kb
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: 22ms
memory: 23448kb
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 1 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 0 0 0 0 1 1 0 1 ...
result:
ok Good plan
Test #3:
score: 0
Accepted
time: 18ms
memory: 17568kb
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 0 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 0 1 0 1 0 0 0 1 0 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 0 1 0 0 1 ...
result:
ok Good plan
Test #4:
score: 0
Accepted
time: 7ms
memory: 17456kb
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: -100
Wrong Answer
time: 28ms
memory: 31264kb
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:
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 1 0 0 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 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 1 0 ...
result:
wrong answer Invalid plan and answer should be No