結果

問題 No.2277 Honest or Dishonest ?
ユーザー cho435cho435
提出日時 2023-04-21 22:35:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 207,940 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-04-25 19:03:12
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 84 ms
7,680 KB
testcase_04 AC 84 ms
8,704 KB
testcase_05 AC 31 ms
6,940 KB
testcase_06 AC 74 ms
6,944 KB
testcase_07 AC 56 ms
6,944 KB
testcase_08 AC 23 ms
6,940 KB
testcase_09 AC 51 ms
7,168 KB
testcase_10 AC 43 ms
6,940 KB
testcase_11 AC 21 ms
6,940 KB
testcase_12 AC 37 ms
6,940 KB
testcase_13 AC 81 ms
7,296 KB
testcase_14 AC 44 ms
6,944 KB
testcase_15 AC 25 ms
6,944 KB
testcase_16 AC 58 ms
6,944 KB
testcase_17 AC 29 ms
6,940 KB
testcase_18 AC 80 ms
8,704 KB
testcase_19 AC 81 ms
8,448 KB
testcase_20 AC 65 ms
7,296 KB
testcase_21 AC 58 ms
6,940 KB
testcase_22 AC 53 ms
6,944 KB
testcase_23 AC 82 ms
6,940 KB
testcase_24 AC 47 ms
6,944 KB
testcase_25 AC 58 ms
7,936 KB
testcase_26 AC 14 ms
6,944 KB
testcase_27 AC 39 ms
6,940 KB
testcase_28 AC 26 ms
6,944 KB
testcase_29 AC 40 ms
6,944 KB
testcase_30 AC 35 ms
6,944 KB
testcase_31 AC 57 ms
6,940 KB
testcase_32 AC 37 ms
6,940 KB
testcase_33 AC 79 ms
8,192 KB
testcase_34 AC 84 ms
8,064 KB
testcase_35 AC 9 ms
6,940 KB
testcase_36 AC 53 ms
6,948 KB
testcase_37 AC 84 ms
6,944 KB
testcase_38 AC 19 ms
6,940 KB
testcase_39 AC 27 ms
6,940 KB
testcase_40 AC 10 ms
6,940 KB
testcase_41 AC 92 ms
8,448 KB
testcase_42 AC 61 ms
7,040 KB
testcase_43 AC 99 ms
9,716 KB
testcase_44 AC 105 ms
9,472 KB
testcase_45 AC 102 ms
9,728 KB
testcase_46 AC 100 ms
9,472 KB
testcase_47 AC 104 ms
9,600 KB
testcase_48 AC 102 ms
9,600 KB
testcase_49 AC 96 ms
9,572 KB
testcase_50 AC 95 ms
9,728 KB
testcase_51 AC 99 ms
9,600 KB
testcase_52 AC 102 ms
9,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

int main(){
  int n,q;
  cin>>n>>q;
  vector<vector<pair<int,int>>> g(n);  
  rep(i,q){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    g.at(a).push_back({b,c});
    g.at(b).push_back({a,c});
  }
  vector<int> ans(n,-1);
  int ct=0;
  rep(i,n){
    if(ans.at(i)!=-1) continue;
    ct++;
    ans.at(i)=0;
    queue<int> q;
    q.push(i);
    while(!q.empty()){
      int v=q.front();
      q.pop();
      for(auto [u,c]:g.at(v)){
        if(ans.at(u)!=-1){
          if(ans.at(u)!=(ans.at(v)^c)){
            cout<<0<<endl;
            return 0;
          }
          continue;
        }
        ans.at(u)=ans.at(v)^c;
        q.push(u);
      }
    }
  }
  cout<<mint(2).pow(ct).val()<<endl;
}
0