結果

問題 No.2274 三角彩色
ユーザー risujirohrisujiroh
提出日時 2023-04-14 22:08:46
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,201 bytes
コンパイル時間 4,140 ms
コンパイル使用メモリ 301,144 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 19:33:25
合計ジャッジ時間 4,872 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/dsu>
#include <atcoder/modint>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int64_t N;
  int M, B, Q;
  cin >> N >> M >> B >> Q;

  using atcoder::modint;
  modint::set_mod(B);

  vector<array<int64_t, 2>> edges(M);
  for (auto& [i, j] : edges) {
    cin >> i >> j;
  }

  vector<int64_t> U;
  for (auto [i, j] : edges) {
    U.push_back(i);
    U.push_back(j);
  }
  ranges::sort(U);
  U.erase(begin(ranges::unique(U)), end(U));

  atcoder::dsu d(size(U));
  modint all = 1;
  for (auto [i, j] : edges) {
    auto ti = ranges::lower_bound(U, i) - begin(U);
    auto tj = ranges::lower_bound(U, j) - begin(U);
    if (d.same(ti, tj)) {
      all *= 2;
    } else {
      d.merge(ti, tj);
    }
  }

  vector<bitset<400>> v;
  while (Q--) {
    bitset<400> cur;
    for (int _ = 3; _--;) {
      int i;
      cin >> i;
      cur[i] = 1;
    }
    for (const auto& e : v) {
      auto pos = e._Find_first();
      if (cur[pos]) {
        cur ^= e;
      }
    }
    if (cur.any()) {
      v.push_back(cur);
    }
  }

  auto ans = modint(2).pow(size(v));
  cout << (all - ans).val() << ' ' << ans.val() << '\n';
}
0