結果

問題 No.1878 union-find の数え上げ
ユーザー Eki1009Eki1009
提出日時 2022-03-18 21:38:52
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 292 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 10,580 KB
実行使用メモリ 45,084 KB
最終ジャッジ日時 2023-07-26 22:42:21
合計ジャッジ時間 3,441 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 16 ms
7,756 KB
testcase_08 AC 15 ms
7,760 KB
testcase_09 AC 15 ms
7,824 KB
testcase_10 AC 15 ms
7,772 KB
testcase_11 AC 15 ms
7,792 KB
testcase_12 AC 16 ms
7,820 KB
testcase_13 WA -
testcase_14 AC 253 ms
19,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
mod = 998244353
n = int(input())
G = [[] for _ in range(n)]
for i in range(1,n):
  p = int(input())-1
  G[p].append(i)
def dfs(u,d):
  res = 1
  for v in G[u]:
    res = res*dfs(v,d+1)%mod
  if d >= 2:
    res = (res+1)%mod
  return res
print(dfs(0,0))
0