結果

問題 No.2277 Honest or Dishonest ?
ユーザー 👑 timitimi
提出日時 2023-04-21 22:48:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 93,260 KB
最終ジャッジ日時 2024-04-25 19:04:05
合計ジャッジ時間 10,904 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,488 KB
testcase_01 AC 41 ms
55,552 KB
testcase_02 AC 42 ms
54,632 KB
testcase_03 AC 213 ms
88,148 KB
testcase_04 AC 214 ms
91,336 KB
testcase_05 AC 128 ms
84,140 KB
testcase_06 AC 174 ms
86,184 KB
testcase_07 AC 150 ms
83,920 KB
testcase_08 AC 120 ms
83,836 KB
testcase_09 AC 174 ms
86,868 KB
testcase_10 AC 128 ms
82,316 KB
testcase_11 AC 100 ms
78,744 KB
testcase_12 AC 115 ms
80,736 KB
testcase_13 AC 198 ms
87,192 KB
testcase_14 AC 113 ms
80,788 KB
testcase_15 AC 121 ms
83,176 KB
testcase_16 AC 155 ms
83,760 KB
testcase_17 AC 108 ms
78,908 KB
testcase_18 AC 215 ms
90,588 KB
testcase_19 AC 210 ms
90,564 KB
testcase_20 AC 176 ms
86,888 KB
testcase_21 AC 135 ms
81,948 KB
testcase_22 AC 160 ms
85,676 KB
testcase_23 AC 177 ms
85,832 KB
testcase_24 AC 148 ms
85,156 KB
testcase_25 AC 180 ms
88,344 KB
testcase_26 AC 109 ms
82,472 KB
testcase_27 AC 121 ms
81,668 KB
testcase_28 AC 137 ms
83,396 KB
testcase_29 AC 159 ms
85,608 KB
testcase_30 AC 130 ms
81,888 KB
testcase_31 AC 167 ms
85,740 KB
testcase_32 AC 148 ms
84,996 KB
testcase_33 AC 215 ms
89,488 KB
testcase_34 AC 220 ms
89,692 KB
testcase_35 AC 94 ms
80,344 KB
testcase_36 AC 166 ms
83,796 KB
testcase_37 AC 194 ms
86,132 KB
testcase_38 AC 87 ms
78,244 KB
testcase_39 AC 101 ms
78,348 KB
testcase_40 AC 96 ms
80,036 KB
testcase_41 AC 229 ms
89,220 KB
testcase_42 AC 178 ms
86,464 KB
testcase_43 AC 258 ms
92,884 KB
testcase_44 AC 274 ms
92,836 KB
testcase_45 AC 261 ms
93,100 KB
testcase_46 AC 267 ms
92,768 KB
testcase_47 AC 256 ms
93,068 KB
testcase_48 AC 254 ms
93,260 KB
testcase_49 AC 260 ms
92,852 KB
testcase_50 AC 243 ms
92,768 KB
testcase_51 AC 259 ms
92,904 KB
testcase_52 AC 260 ms
93,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
  from sys import stdin, setrecursionlimit
  input = stdin.readline
  readline = stdin.readline
  N,Q=map(int, input().split())
  D=[[] for i in range(N)]
  for i in range(Q):
    a,b,c=map(int, input().split())
    a-=1
    b-=1
    D[a].append((b,c))
    D[b].append((a,c))
    
  ans=1;mod=998244353 
  V=[-1]*N
  from collections import deque
  for i in range(N):
    if V[i]==-1:
      v=0
      d=deque()
      d.append(i)
      V[i]=0
      while d:
        now=d.popleft()
        for nex,c in D[now]:
          if V[nex]==-1:
            if V[now]==c:
              V[nex]=0
            else:
              V[nex]=1
            d.append(nex)
          else:
            if V[now]==c:
              f=0
            else:
              f=1 
            if V[nex]!=f:
              v=1 
      ans*=(2-2*v)
      ans%=mod
  print(ans)
main()
0