結果

問題 No.1878 union-find の数え上げ
ユーザー 👑 rin204rin204
提出日時 2022-03-18 22:31:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 355 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 91,280 KB
最終ジャッジ日時 2024-04-14 12:11:38
合計ジャッジ時間 2,575 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
87,864 KB
testcase_01 AC 168 ms
84,728 KB
testcase_02 AC 168 ms
84,940 KB
testcase_03 AC 165 ms
84,908 KB
testcase_04 AC 163 ms
84,436 KB
testcase_05 AC 94 ms
78,384 KB
testcase_06 AC 91 ms
78,044 KB
testcase_07 AC 38 ms
53,260 KB
testcase_08 AC 37 ms
53,064 KB
testcase_09 AC 37 ms
52,900 KB
testcase_10 AC 37 ms
51,952 KB
testcase_11 AC 37 ms
52,364 KB
testcase_12 AC 38 ms
53,624 KB
testcase_13 AC 38 ms
53,140 KB
testcase_14 AC 120 ms
91,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

n = int(input())
edges = [[] for _ in range(n)]
for i in range(1, n):
    p = int(input()) - 1
    edges[p].append(i)
    
dist = [0] * n
stack = [0]
ans = 1
while stack:
    pos = stack.pop()
    for npos in edges[pos]:
        dist[npos] = dist[pos] + 1
        ans *= dist[npos]
        ans %= MOD
        stack.append(npos)
print(ans)
0