QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#917982#997. 2-SAT 问题Floze3#WA 18ms14664kbC++207.5kb2025-02-27 16:22:192025-02-27 16:22:26

Judging History

This is the latest submission verdict.

  • [2025-02-27 16:22:26]
  • Judged
  • Verdict: WA
  • Time: 18ms
  • Memory: 14664kb
  • [2025-02-27 16:22:19]
  • Submitted

answer

#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#ifdef CPH
#include "/home/floze3/OI/debug.hpp"
#else 
#include "/home/floze3/OI/debug_colored.hpp"
#endif
#else
#define debug(...) 42
#define debugArr(...) 42
#define look_time 42
#define look_memory 42
#endif
#define mp(x, y) std::make_pair(x, y)
#define mt std::make_tuple
#define eb emplace_back
#define fi first
#define se second
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define file(name)                 \
  freopen(name ".in", "r", stdin); \
  freopen(name ".out", "w", stdout);
#define fs(x) std::fixed << std::setprecision(x)
#define il inline
#define Avada_Kedavra return 0
#define _IOS                        \
  std::ios::sync_with_stdio(false); \
  std::cin.tie(nullptr), std::cout.tie(nullptr)
#define RANDOM_SEED std::chrono::steady_clock::now().time_since_epoch().count()
#define multitask    \
  int _; rd >> _; \
  while (_--)
using std::cerr;

namespace TYPEDEF {

using i32 = int32_t;
using i64 = long long;
using u64 = unsigned long long;
using u32 = uint32_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using pii = std::pair<i32, i32>;
using pi64 = std::pair<i64, i64>;
using vi = std::vector<i32>;
using vu = std::vector<u32>;
using vi64 = std::vector<i64>;
using vu64 = std::vector<u64>;
using vpii = std::vector<pii>;
using vpi64 = std::vector<pi64>;
using si = std::stack<i32>;
using si64 = std::stack<i64>;
using su64 = std::stack<u64>;
using spii = std::stack<pii>;
using spi64 = std::stack<pi64>;
using qi = std::queue<i32>;
using qi64 = std::queue<i64>;
using qu64 = std::queue<u64>;
using qpii = std::queue<pii>;
using qpi64 = std::queue<pi64>;
using siset = std::set<i32>;
using si64set = std::set<i64>;
using su64set = std::set<u64>;
using spiiset = std::set<pii>;
using spi64set = std::set<pi64>;
using str = std::string;
using vstr = std::vector<str>;
using f64 = long double;
template <typename T> using vc = std::vector<T>;
template <typename FI, typename SE> using pr = std::pair<FI, SE>;

} // namespaec TYPEDEF

using namespace TYPEDEF;

struct Scanner {
  FILE* stream;
  Scanner(FILE* s): stream(s) {}
  char buf[1 << 20], *l = buf, *r = buf;
  bool flush() { l = buf; r = l + fread(buf, 1, 1 << 20, stream); return l == r; }
  void get(char &c) {
#ifndef ONLINE_JUDGE
    c = getchar();
#else
    c = l == r && flush() ? ' ' : *l++;
#endif
  }

  friend Scanner &operator>>(Scanner &in, char &c) { return in.get(c), in; }

  friend Scanner &operator>>(Scanner &in, char* s) {
    for (in.get(s[0]); isspace(s[0]); in.get(s[0]));
    for (i32 i = 0; !isspace(s[i]) || (s[i] = '\0'); i++) in.get(s[i + 1]);
    return in;
  }

  friend Scanner &operator>>(Scanner &in, str &s) {
    char c;
    for (in.get(c); isspace(c); in.get(c));
    for (s = ""; !isspace(c); in.get(c)) s += c;
    return in;
  }

  friend Scanner &operator>>(Scanner &in, i128 &x) {
    char c, f = '+';
    for (in.get(c); !isdigit(c); in.get(c))
      if (c == '-') f = c;
    for (x = 0; isdigit(c); in.get(c)) x = (x << 1) + (x << 3) + c - '0';
    if (f == '-') x = -x;
    return in;
  }

  template <class T> requires std::is_integral_v<T>
  friend Scanner &operator>>(Scanner &in, T &x) {
    char c, f = '+';
    for (in.get(c); !isdigit(c); in.get(c))
      if constexpr (std::is_signed_v<T>) f = c;
    for (x = 0; isdigit(c); in.get(c)) x = x * 10 + c - '0';
    if constexpr (std::is_signed_v<T>) x = f == '-' ? -x : x;
    return in;
  }

  template <class T> requires std::is_floating_point_v<T>
  friend Scanner &operator>>(Scanner &in, T &x) {
    std::string s; in >> s; x = std::stod(s);
    return in;
  }
};

struct Printer {
  FILE* stream;
  Printer(FILE* s): stream(s) {}
  char buf[1 << 20], *l = buf, *r = buf + (1 << 20) - 1;
  int format = 0, precision = 15;
  ~Printer() { flush(); }

  void flush() { fwrite(buf, 1, l - buf, stream); l = buf; }
  void put(const char &c) {
#ifndef ONLINE_JUDGE
    putchar(c);
#else
    *l++ = c;
    if (l == r) flush();
#endif
  }

  friend Printer &operator<<(Printer &out, const char &c) {
    return out.put(c), out;
  }

  friend Printer &operator<<(Printer &out, const char* s) {
    for (int i = 0; s[i] != '\0'; i++) out.put(s[i]);
    return out;
  }

  friend Printer &operator<<(Printer &out, char* s) {
    for (int i = 0; s[i] != '\0'; i++) out.put(s[i]);
    return out;
  }

  friend Printer &operator<<(Printer &out, const str &s) {
    for (int i = 0, n = s.size(); i < n; i++) out.put(s[i]);
    return out;
  }

  friend Printer &operator<<(Printer &out, i128 x) {
    static short s[40], top = 0;
    if (x < 0) out.put('-'), x = -x;
    do s[++top] = x % 10, x /= 10; while (x);
    while (top) out.put(s[top--] + '0');
    return out;
  }

  template <typename T> requires std::is_integral_v<T>
  friend Printer& operator <<(Printer &out, T x) {
    static short s[40];
    static i32 i = 0;
    if (x == 0) { out.put('0'); return out; }
    if constexpr (std::is_signed_v<T>) x = x < 0 ? out.put('-'), -x : x;
    while (x > 0) s[++i] = x % 10 + '0', x /= 10;
    while (i > 0) out.put(s[i--]);
    return out;
  }

  template <typename T> requires std::is_floating_point_v<T>
  friend Printer& operator <<(Printer &out, T x) {
    std::ostringstream oss;
    oss << std::fixed << std::setprecision(out.precision) << x;
    return out << oss.str();
  }
};

Scanner rd(stdin);
Printer wt(stdout);

/*===============================ALGOS===============================*/

namespace basic_algorithm {
template <typename T> il T abs(T a) { return a >= 0 ? a : -a; }
template <typename T> il void chmin(T &a, T b) { if (a > b) a = b; }
template <typename T> il void chmax(T &a, T b) { if (a < b) a = b; }
template <typename T> il T lowbit(T x) { return (x & (-x)); }
il i32 pct(i32 x) { return __builtin_popcount(x); }
il i32 pct(u32 x) { return __builtin_popcount(x); }
il i32 pct(i64 x) { return __builtin_popcountll(x); }
il i32 pct(u64 x) { return __builtin_popcountll(x); }
}  // namespace basic_algorithm

using namespace basic_algorithm;

/*================================END================================*/

constexpr i32 N = 1e5 + 5;
constexpr i32 mod = 1e9 + 7;
constexpr i32 inf = 0x3f3f3f3f;
constexpr i64 inf64 = 0x3f3f3f3f3f3f3f3fll;
// constexpr f64 pi = std::numbers::pi_v<f64>;

// std::mt19937 rng(RANDOM_SEED);

bool mst;

i32 n, m, scc_id[N << 1], scc_cnt, dfn[N << 1], low[N << 1], dfc, st[N << 1], top; // 1 ~ n 真 n + 1 ~ 2 * n 假
bool in_sta[N << 1];

vi g[N << 1];

void tarjan(i32 u) {
  dfn[u] = low[u] = ++dfc, st[++top] = u, in_sta[u] = true;
  for (i32 v : g[u]) {
    if (!dfn[v]) tarjan(v), chmin(low[u], low[v]);
    else if (in_sta[v]) chmin(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    ++scc_cnt;
    do {
      scc_id[st[top]] = scc_cnt;
      in_sta[st[top--]] = false;
    } while (st[top + 1] != u);
  }
  return ;
}

bool med;

signed main() {
  rd >> n >> m;
  for (i32 i = 1, a, b, c, d; i <= m; ++i) {
    rd >> a >> b >> c >> d;
    g[a + b * n].eb(c + (d ^ 1) * n);
    g[c + d * n].eb(a + (b ^ 1) * n);
  }
  for (i32 i = 1; i <= n; ++i)
    if (!dfn[i]) tarjan(i);
  for (i32 i = 1; i <= n; ++i)
    if (scc_id[i] == scc_id[i + n]) return wt << "No", 0;
  wt << "Yes\n";
  for (i32 i = 1; i <= n; ++i)
    wt << (scc_id[i] < scc_id[i + n]) << ' ';
  Avada_Kedavra;
}

/*
all the things you do
the words you say
it all comes back to you
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 18ms
memory: 14664kb

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 1 1 1 0 0 0 0 0 0 1 0 0 1 1 1 1 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 0 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 0 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 0 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0 0 1 0 0 ...

result:

wrong answer Your plan didn't satisfy condition #7.(i = 2994, a = 1, j = 84183, b = 1)