結果

問題 No.1878 union-find の数え上げ
ユーザー wolgnikwolgnik
提出日時 2022-03-18 21:47:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 448 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 89,356 KB
最終ジャッジ日時 2024-04-14 12:07:58
合計ジャッジ時間 2,228 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 37 ms
53,788 KB
testcase_08 AC 37 ms
52,324 KB
testcase_09 AC 37 ms
52,332 KB
testcase_10 AC 37 ms
52,324 KB
testcase_11 AC 37 ms
53,560 KB
testcase_12 AC 37 ms
52,440 KB
testcase_13 WA -
testcase_14 AC 86 ms
89,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
mod = 998244353

e = [[] for _ in range(N + 1)]
for x in range(2, N + 1):
  p = int(input())
  e[p].append(x)

s = [1]
vis = [0] * (N + 1)
vis[1] = 1
depth = [0] * (N + 1)
while len(s):
  x = s.pop()
  for y in e[x]:
    if vis[y]: continue
    vis[y] = 1
    s.append(y)
    depth[y] = depth[x] + 1

res = 1
for x in range(2, N + 1):
  if depth[x] > 1:
    res *= 2
    res %= mod
print(res)
0