結果

問題 No.2277 Honest or Dishonest ?
ユーザー 👑 kakel-sankakel-san
提出日時 2023-07-24 10:00:57
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 267 ms / 2,000 ms
コード長 1,779 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 111,996 KB
実行使用メモリ 46,608 KB
最終ジャッジ日時 2024-04-08 11:28:35
合計ジャッジ時間 14,046 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
25,436 KB
testcase_01 AC 35 ms
25,436 KB
testcase_02 AC 33 ms
25,436 KB
testcase_03 AC 212 ms
41,528 KB
testcase_04 AC 217 ms
43,532 KB
testcase_05 AC 92 ms
33,980 KB
testcase_06 AC 178 ms
39,796 KB
testcase_07 AC 162 ms
38,496 KB
testcase_08 AC 77 ms
32,516 KB
testcase_09 AC 147 ms
37,256 KB
testcase_10 AC 116 ms
33,788 KB
testcase_11 AC 69 ms
30,764 KB
testcase_12 AC 108 ms
31,756 KB
testcase_13 AC 205 ms
41,652 KB
testcase_14 AC 132 ms
33,172 KB
testcase_15 AC 87 ms
35,104 KB
testcase_16 AC 153 ms
38,620 KB
testcase_17 AC 86 ms
31,476 KB
testcase_18 AC 194 ms
41,800 KB
testcase_19 AC 214 ms
44,772 KB
testcase_20 AC 169 ms
41,212 KB
testcase_21 AC 147 ms
37,152 KB
testcase_22 AC 136 ms
36,396 KB
testcase_23 AC 192 ms
39,920 KB
testcase_24 AC 134 ms
38,264 KB
testcase_25 AC 160 ms
39,460 KB
testcase_26 AC 57 ms
31,332 KB
testcase_27 AC 105 ms
34,280 KB
testcase_28 AC 84 ms
34,352 KB
testcase_29 AC 119 ms
37,276 KB
testcase_30 AC 97 ms
32,692 KB
testcase_31 AC 150 ms
36,872 KB
testcase_32 AC 106 ms
34,820 KB
testcase_33 AC 195 ms
40,936 KB
testcase_34 AC 214 ms
44,380 KB
testcase_35 AC 51 ms
32,052 KB
testcase_36 AC 126 ms
34,888 KB
testcase_37 AC 197 ms
41,076 KB
testcase_38 AC 67 ms
30,268 KB
testcase_39 AC 80 ms
31,228 KB
testcase_40 AC 50 ms
31,456 KB
testcase_41 AC 210 ms
42,628 KB
testcase_42 AC 164 ms
40,468 KB
testcase_43 AC 227 ms
45,068 KB
testcase_44 AC 258 ms
46,608 KB
testcase_45 AC 259 ms
46,608 KB
testcase_46 AC 267 ms
46,608 KB
testcase_47 AC 253 ms
46,608 KB
testcase_48 AC 260 ms
46,476 KB
testcase_49 AC 237 ms
46,092 KB
testcase_50 AC 232 ms
44,940 KB
testcase_51 AC 252 ms
46,608 KB
testcase_52 AC 224 ms
45,068 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, q) = (c[0], c[1]);
        var map = NArr(q);
        var tree = new List<(int to, int val)>[n];
        for (var i = 0; i < tree.Length; ++i) tree[i] = new List<(int to, int val)>();
        foreach (var edge in map)
        {
            tree[edge[0] - 1].Add((edge[1] - 1, edge[2]));
            tree[edge[1] - 1].Add((edge[0] - 1, edge[2]));
        }
        var ans = 1L;
        var mod = 998_244_353;
        var len = Enumerable.Repeat(-1, n).ToArray();
        for (var i = 0; i < n; ++i)
        {
            if (len[i] < 0)
            {
                len[i] = 0;
                ans = ans * 2 % mod;
                if (!DFS(i, tree, len))
                {
                    WriteLine(0);
                    return;
                }
            }
        }
        WriteLine(ans);
    }
    static bool DFS(int cur, List<(int to, int val)>[] tree, int[] len)
    {
        foreach (var next in tree[cur])
        {
            if (len[next.to] < 0)
            {
                len[next.to] = len[cur] ^ next.val;
                if (!DFS(next.to, tree, len)) return false;
            }
            else
            {
                if (len[next.to] != (len[cur] ^ next.val)) return false;
            }
        }
        return true;
    }
}
0