結果

問題 No.2277 Honest or Dishonest ?
ユーザー Shreyan RayShreyan Ray
提出日時 2023-04-21 21:58:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,554 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 198,648 KB
実行使用メモリ 13,388 KB
最終ジャッジ日時 2024-04-25 18:46:32
合計ジャッジ時間 5,710 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 46 ms
12,544 KB
testcase_04 AC 43 ms
12,032 KB
testcase_05 AC 14 ms
7,936 KB
testcase_06 AC 36 ms
11,372 KB
testcase_07 AC 33 ms
10,240 KB
testcase_08 AC 12 ms
7,628 KB
testcase_09 AC 29 ms
9,344 KB
testcase_10 AC 24 ms
9,344 KB
testcase_11 AC 11 ms
7,444 KB
testcase_12 AC 17 ms
8,536 KB
testcase_13 AC 44 ms
12,032 KB
testcase_14 AC 20 ms
9,088 KB
testcase_15 AC 13 ms
7,492 KB
testcase_16 AC 32 ms
10,368 KB
testcase_17 AC 17 ms
8,192 KB
testcase_18 AC 40 ms
11,468 KB
testcase_19 AC 42 ms
11,616 KB
testcase_20 AC 34 ms
10,580 KB
testcase_21 AC 32 ms
10,368 KB
testcase_22 AC 33 ms
9,856 KB
testcase_23 AC 42 ms
11,812 KB
testcase_24 AC 25 ms
9,472 KB
testcase_25 AC 29 ms
9,800 KB
testcase_26 AC 7 ms
7,040 KB
testcase_27 AC 22 ms
8,960 KB
testcase_28 AC 14 ms
7,888 KB
testcase_29 AC 21 ms
8,632 KB
testcase_30 AC 20 ms
9,288 KB
testcase_31 AC 33 ms
10,752 KB
testcase_32 AC 19 ms
8,192 KB
testcase_33 AC 41 ms
11,648 KB
testcase_34 AC 49 ms
12,624 KB
testcase_35 AC 6 ms
6,944 KB
testcase_36 AC 32 ms
10,240 KB
testcase_37 AC 44 ms
12,160 KB
testcase_38 AC 10 ms
7,384 KB
testcase_39 AC 14 ms
8,140 KB
testcase_40 AC 5 ms
6,944 KB
testcase_41 AC 50 ms
13,388 KB
testcase_42 AC 35 ms
10,880 KB
testcase_43 AC 51 ms
13,260 KB
testcase_44 AC 57 ms
13,128 KB
testcase_45 AC 57 ms
13,136 KB
testcase_46 AC 56 ms
13,260 KB
testcase_47 AC 54 ms
13,312 KB
testcase_48 AC 55 ms
13,184 KB
testcase_49 AC 55 ms
13,260 KB
testcase_50 AC 53 ms
13,184 KB
testcase_51 AC 51 ms
13,388 KB
testcase_52 AC 55 ms
13,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 69;
const int mod = 998244353;
vector <pair<int, int>> adj[N];
int col[N];
bool vis[N];
int n, q;

void dfs(int u, int c){
    col[u] = c;
    vis[u] = true;
    for (auto [v, w] : adj[u]){
        if (!vis[v]){
            dfs(v, c ^ w);
        }
    }
}

void Solve() 
{
    cin >> n >> q;
    int ans = 1;
    for (int i = 1; i <= q; i++){
        int u, v, d; cin >> u >> v >> d;
        adj[u].push_back({v, d});
        adj[v].push_back({u, d});
    }
    
    for (int i = 1; i <= n; i++){
        if (!vis[i]){
            ans *= 2;
            ans %= mod;
            dfs(i, 0);
        }
    }
    
    for (int i = 1; i <= n; i++){
        for (auto [v, w]: adj[i]){
            if (col[v] ^ col[i] != w){
                cout << 0 << "\n";
                return;
            }
        }
    }
    
    cout << ans << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
   // cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
   // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
0