結果

問題 No.2277 Honest or Dishonest ?
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2023-04-21 22:15:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 3,119 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 203,244 KB
実行使用メモリ 10,316 KB
最終ジャッジ日時 2024-04-25 18:59:32
合計ジャッジ時間 6,583 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 83 ms
8,320 KB
testcase_04 AC 80 ms
8,960 KB
testcase_05 AC 25 ms
6,944 KB
testcase_06 AC 68 ms
7,168 KB
testcase_07 AC 56 ms
6,940 KB
testcase_08 AC 18 ms
6,940 KB
testcase_09 AC 47 ms
7,296 KB
testcase_10 AC 41 ms
6,940 KB
testcase_11 AC 19 ms
6,940 KB
testcase_12 AC 34 ms
6,944 KB
testcase_13 AC 76 ms
7,936 KB
testcase_14 AC 40 ms
6,944 KB
testcase_15 AC 20 ms
6,944 KB
testcase_16 AC 52 ms
6,940 KB
testcase_17 AC 27 ms
6,944 KB
testcase_18 AC 74 ms
8,704 KB
testcase_19 AC 77 ms
8,832 KB
testcase_20 AC 61 ms
7,552 KB
testcase_21 AC 54 ms
6,944 KB
testcase_22 AC 50 ms
7,168 KB
testcase_23 AC 74 ms
7,296 KB
testcase_24 AC 43 ms
6,944 KB
testcase_25 AC 50 ms
7,680 KB
testcase_26 AC 10 ms
6,944 KB
testcase_27 AC 35 ms
6,944 KB
testcase_28 AC 23 ms
6,944 KB
testcase_29 AC 36 ms
7,040 KB
testcase_30 AC 35 ms
6,944 KB
testcase_31 AC 59 ms
7,552 KB
testcase_32 AC 32 ms
6,944 KB
testcase_33 AC 75 ms
8,704 KB
testcase_34 AC 85 ms
9,088 KB
testcase_35 AC 8 ms
6,940 KB
testcase_36 AC 49 ms
6,944 KB
testcase_37 AC 82 ms
7,936 KB
testcase_38 AC 18 ms
6,940 KB
testcase_39 AC 24 ms
6,940 KB
testcase_40 AC 8 ms
6,944 KB
testcase_41 AC 86 ms
9,216 KB
testcase_42 AC 59 ms
7,552 KB
testcase_43 AC 86 ms
9,984 KB
testcase_44 AC 101 ms
9,984 KB
testcase_45 AC 92 ms
10,180 KB
testcase_46 AC 94 ms
9,984 KB
testcase_47 AC 97 ms
10,112 KB
testcase_48 AC 97 ms
10,176 KB
testcase_49 AC 88 ms
10,316 KB
testcase_50 AC 87 ms
9,856 KB
testcase_51 AC 89 ms
10,208 KB
testcase_52 AC 84 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
const long long MD = 998244353;
template<long long MOD=MD> struct mdint {
    int d=0;
    mdint () {d=0;}
    mdint (long long _d) : d(_d%MOD){
        if(d<0) d+=MOD;
    };
    friend mdint& operator+=(mdint& a, const mdint& o) {
        a.d+=o.d; if(a.d>=MOD) a.d-=MOD;
        return a;
    }
    friend mdint& operator-=(mdint& a, const mdint& o) {
        a.d-=o.d; if(a.d<0) a.d+=MOD;
        return a;
    }
    friend mdint& operator*=(mdint& a, const mdint& o) {
        return a = mdint((ll)a.d*o.d);
    }
    mdint operator*(const mdint& o) const {
        mdint res = *this;
        res*=o;
        return res;
    }
    mdint operator+(const mdint& o) const {
        mdint res = *this;
        res+=o;
        return res;
    }
    mdint operator-(const mdint& o) const {
        mdint res = *this;
        res-=o;
        return res;
    }
    mdint operator^(long long b) const {
        mdint tmp = 1;
        mdint power = *this;
        while(b) {
            if(b&1) {
                tmp = tmp*power;
            }
            power = power*power;
            b/=2;
        }
        return tmp;
    }
    friend mdint operator/=(mdint& a, const mdint& o) {
        a *= (o^(MOD-2));
        return a;
    }
    mdint operator/(const mdint& o) {
        mdint res = *this;
        res/=o;
        return res;
    }
    bool operator==(const mdint& o) { return d==o.d;}
    bool operator!=(const mdint& o) { return d!=o.d;}
    friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;}
    friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;}
};
using  mint = mdint<MD>;
int main() {
    int n,q; cin >> n >>q;
    // c[i]
    vector<vector<pi>> adj(n);
    while(q--) {
        int a,b,c; cin >> a >> b >> c;
        --a,b--;
        // honest --> honest, honest, liar liar
        adj[b].push_back({a,c});
        adj[a].push_back({b,c});
    }
    mint ans=1;
    vector<char> vis(n),col(n);
    auto dfs = [&](auto&& self, int at) -> void {
        vis[at]=1;
        for(auto [to,c] : adj[at]) {
            if(!vis[to]) {
                col[to] = col[at]^c;
                self(self,to);
            } else {
                if( (col[at]^c) !=col[to]) {
                    cout << "0\n";
                    exit(0);
                }
            }
        }
    };
    for(int i=0;i<n;++i) if(!vis[i]) {
        ans*=2;
        dfs(dfs,i);
    }
    cout << ans << '\n';
}
0