結果

問題 No.2277 Honest or Dishonest ?
ユーザー HaaHaa
提出日時 2023-04-21 22:00:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 1,487 ms
コンパイル使用メモリ 173,720 KB
実行使用メモリ 13,036 KB
最終ジャッジ日時 2023-08-08 00:42:45
合計ジャッジ時間 6,698 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 89 ms
11,280 KB
testcase_04 AC 85 ms
11,468 KB
testcase_05 AC 26 ms
6,676 KB
testcase_06 AC 75 ms
9,736 KB
testcase_07 AC 58 ms
8,520 KB
testcase_08 AC 19 ms
6,616 KB
testcase_09 AC 53 ms
8,268 KB
testcase_10 AC 44 ms
7,192 KB
testcase_11 AC 20 ms
5,092 KB
testcase_12 AC 36 ms
6,168 KB
testcase_13 AC 84 ms
10,620 KB
testcase_14 AC 44 ms
6,852 KB
testcase_15 AC 22 ms
6,152 KB
testcase_16 AC 58 ms
8,472 KB
testcase_17 AC 28 ms
5,800 KB
testcase_18 AC 77 ms
10,616 KB
testcase_19 AC 81 ms
10,876 KB
testcase_20 AC 66 ms
9,396 KB
testcase_21 AC 60 ms
8,056 KB
testcase_22 AC 53 ms
8,464 KB
testcase_23 AC 80 ms
9,296 KB
testcase_24 AC 46 ms
7,800 KB
testcase_25 AC 57 ms
8,776 KB
testcase_26 AC 12 ms
6,152 KB
testcase_27 AC 39 ms
6,592 KB
testcase_28 AC 24 ms
6,152 KB
testcase_29 AC 38 ms
7,448 KB
testcase_30 AC 37 ms
6,784 KB
testcase_31 AC 64 ms
9,216 KB
testcase_32 AC 35 ms
6,944 KB
testcase_33 AC 81 ms
11,176 KB
testcase_34 AC 95 ms
11,744 KB
testcase_35 AC 8 ms
4,812 KB
testcase_36 AC 56 ms
8,200 KB
testcase_37 AC 86 ms
10,428 KB
testcase_38 AC 19 ms
4,820 KB
testcase_39 AC 27 ms
5,520 KB
testcase_40 AC 8 ms
4,540 KB
testcase_41 AC 101 ms
12,040 KB
testcase_42 AC 67 ms
9,384 KB
testcase_43 AC 108 ms
13,008 KB
testcase_44 AC 110 ms
12,884 KB
testcase_45 AC 102 ms
13,012 KB
testcase_46 AC 104 ms
13,004 KB
testcase_47 AC 102 ms
13,008 KB
testcase_48 AC 104 ms
12,928 KB
testcase_49 AC 105 ms
12,956 KB
testcase_50 AC 106 ms
12,952 KB
testcase_51 AC 107 ms
12,952 KB
testcase_52 AC 104 ms
13,036 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