結果

問題 No.2277 Honest or Dishonest ?
ユーザー miscalc
提出日時 2023-04-19 23:52:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 882 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 201,652 KB
最終ジャッジ日時 2025-02-12 10:27:19
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 19 WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using namespace atcoder;
using mint = modint1000000007;

int main()
{
  int N, Q;
  cin >> N >> Q;
  vector<vector<pair<int, int>>> G(N);
  for (int i = 0; i < Q; i++)
  {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G.at(a).push_back({b, c});
    G.at(b).push_back({a, c});
  }

  mint ans = 1;
  vector<int> colors(N, -1);
  auto dfs = [&](auto self, int v) -> void
  {
    for (auto [nv, d] : G.at(v))
    {
      int new_color = colors.at(v) ^ d;
      if (colors.at(nv) == -1)
      {
        colors.at(nv) = new_color;
        self(self, nv);
      }
      else if (colors.at(nv) != new_color)
        ans *= 0;
    }
  };
  for (int v = 0; v < N; v++)
  {
    if (colors.at(v) == -1)
    {
      ans *= 2;
      colors.at(v) = 0;
      dfs(dfs, v);
    }
  }
  cout << ans.val() << endl;
}
0