結果

問題 No.2277 Honest or Dishonest ?
ユーザー HaaHaa
提出日時 2023-04-21 22:00:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 172,604 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-25 18:46:26
合計ジャッジ時間 6,925 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 93 ms
11,392 KB
testcase_04 AC 90 ms
11,776 KB
testcase_05 AC 27 ms
7,040 KB
testcase_06 AC 77 ms
9,984 KB
testcase_07 AC 61 ms
8,832 KB
testcase_08 AC 20 ms
7,168 KB
testcase_09 AC 55 ms
8,576 KB
testcase_10 AC 47 ms
7,296 KB
testcase_11 AC 22 ms
6,944 KB
testcase_12 AC 39 ms
6,940 KB
testcase_13 AC 90 ms
11,008 KB
testcase_14 AC 48 ms
7,168 KB
testcase_15 AC 24 ms
6,940 KB
testcase_16 AC 63 ms
9,088 KB
testcase_17 AC 31 ms
6,944 KB
testcase_18 AC 80 ms
10,880 KB
testcase_19 AC 84 ms
11,392 KB
testcase_20 AC 68 ms
9,600 KB
testcase_21 AC 62 ms
8,448 KB
testcase_22 AC 56 ms
8,704 KB
testcase_23 AC 85 ms
9,600 KB
testcase_24 AC 50 ms
8,064 KB
testcase_25 AC 57 ms
9,216 KB
testcase_26 AC 12 ms
6,944 KB
testcase_27 AC 43 ms
6,940 KB
testcase_28 AC 25 ms
6,944 KB
testcase_29 AC 39 ms
7,680 KB
testcase_30 AC 39 ms
7,040 KB
testcase_31 AC 68 ms
9,472 KB
testcase_32 AC 35 ms
7,296 KB
testcase_33 AC 83 ms
11,136 KB
testcase_34 AC 96 ms
11,904 KB
testcase_35 AC 8 ms
6,940 KB
testcase_36 AC 58 ms
8,576 KB
testcase_37 AC 91 ms
10,496 KB
testcase_38 AC 19 ms
6,944 KB
testcase_39 AC 28 ms
6,940 KB
testcase_40 AC 8 ms
6,940 KB
testcase_41 AC 101 ms
12,288 KB
testcase_42 AC 67 ms
9,728 KB
testcase_43 AC 103 ms
13,184 KB
testcase_44 AC 108 ms
13,312 KB
testcase_45 AC 108 ms
13,184 KB
testcase_46 AC 109 ms
13,312 KB
testcase_47 AC 106 ms
13,184 KB
testcase_48 AC 104 ms
13,132 KB
testcase_49 AC 109 ms
13,184 KB
testcase_50 AC 102 ms
13,288 KB
testcase_51 AC 103 ms
13,312 KB
testcase_52 AC 106 ms
13,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T& x, const T& y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int main(){
    int n, q; cin >> n >> q;
    vector<vector<P>> g(n);
    int a, b, c;
    REP(i,q){
        cin >> a >> b >> c;
        a--, b--;
        g[b].push_back({a,c});
        g[a].push_back({b,c});
    }
    VI f(n,-1);
    bool no=0;
    function<void(int)> dfs=[&](int v){
        for(auto p:g[v]){
            int to=p.first, flag=p.second;
            if(f[to]==-1){
                f[to]=(f[v]==flag?0:1);
                dfs(to);
            }
            else if(f[to]!=(f[v]==flag?0:1))
                no=1;
        }
    };
    ll ans=1;
    REP(i,n){
        if(f[i]==-1){
            ans=ans*2%MOD;
            f[i]=0;
            dfs(i);
        }
    }
    if(no) ans=0;
    cout << ans << endl;
    return 0;
}
0