結果

問題 No.2277 Honest or Dishonest ?
コンテスト
ユーザー C
提出日時 2026-10-02 00:21:32
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 47 ms / 2,000 ms
+ 92µs
コード長 1,429 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,268 ms
コンパイル使用メモリ 398,644 KB
実行使用メモリ 12,120 KB
最終ジャッジ日時 2026-10-02 00:21:48
合計ジャッジ時間 14,738 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using pll=pair<ll,ll>;

// using mint=modint;

// template<class K,class V>
// using ordered_map=tree<K,V,less<K>,rb_tree_tag,tree_order_statistics_node_update>;


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

    ll N,Q;
    cin>>N>>Q;
    vector<vector<pll>>g(N);
    rep(i,0,Q){
        ll A,B,C;
        cin>>A>>B>>C;
        --A,--B;
        g[A].push_back({B,C});
        g[B].push_back({A,C});
    }

    vll col(N,-1);
    ll comp=0;

    rep(s,0,N){
        if(col[s]!=-1)continue;
        comp++;
        col[s]=0;
        queue<ll>q;
        q.push(s);
        while(!q.empty()){
            ll u=q.front();
            q.pop();
            for(auto [v,c]:g[u]){
                ll nc=col[u]^c;
                if(col[v]==-1){
                    col[v]=nc;
                    q.push(v);
                }else if(col[v]!=nc){
                    cout<<0<<endl;
                    return 0;
                }
            }
        }
    }
    modint998244353 ans=1;
    rep(i,0,comp)ans*=2;
    cout<<ans.val()<<endl;

}
0