結果

問題 No.2536 同値性と充足可能性
ユーザー 👑 emthrmemthrm
提出日時 2023-11-10 21:44:15
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,464 bytes
コンパイル時間 3,370 ms
コンパイル使用メモリ 259,280 KB
実行使用メモリ 13,412 KB
最終ジャッジ日時 2023-11-10 21:44:21
合計ジャッジ時間 6,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 4 ms
6,676 KB
testcase_23 AC 24 ms
6,676 KB
testcase_24 AC 25 ms
6,676 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

struct UnionFind {
  explicit UnionFind(const int n) : data(n, -1) {}

  int root(const int ver) {
    return data[ver] < 0 ? ver : data[ver] = root(data[ver]);
  }

  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (data[u] > data[v]) std::swap(u, v);
    data[u] += data[v];
    data[v] = u;
    return true;
  }

  bool is_same(const int u, const int v) { return root(u) == root(v); }

  int size(const int ver) { return -data[root(ver)]; }

 private:
  std::vector<int> data;
};

int main() {
  int n, m; cin >> n >> m;
  UnionFind union_find(n * 2);
  while (m--) {
    int i, j; string e; cin >> i >> e >> j; --i; --j;
    if (e == "<==>") {
      union_find.unite(i, j);
      union_find.unite(i + n, j + n);
    } else if (e == "<=/=>") {
      union_find.unite(i, j + n);
      union_find.unite(i + n, j);
    }
  }
  REP(i, n) {
    if (union_find.is_same(i, i + n)) {
      cout << "No\n";
      return 0;
    }
  }
  vector<vector<int>> nodes(n * 2);
  REP(i, n * 2) nodes[union_find.root(i)].emplace_back(i);
  vector<int> is_visited(n, false), ans;
  for (const vector<int>& v : nodes) {
    if (v.empty() || is_visited[v.front() >= n ? v.front() - n : v.front()]) continue;
    array<vector<int>, 2> ar{};
    for (const int v_i : v) {
      ar[v_i >= n].emplace_back(v_i >= n ? v_i - n : v_i);
      is_visited[v_i >= n ? v_i - n : v_i] = true;
    }
    ranges::copy(ar[ar[0].size() > ar[1].size() ? 0 : 1], back_inserter(ans));
  }
  const int l = ans.size();
  cout << "Yes\n" << l << '\n';
  REP(i, l) cout << ans[i] + 1 << " \n"[i + 1 == l];
  return 0;
}
0