結果

問題 No.1878 union-find の数え上げ
ユーザー ytftytft
提出日時 2022-03-19 13:22:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 355 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 78,476 KB
最終ジャッジ日時 2024-04-15 02:32:18
合計ジャッジ時間 1,408 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
78,220 KB
testcase_01 AC 65 ms
78,408 KB
testcase_02 AC 68 ms
78,164 KB
testcase_03 AC 67 ms
78,476 KB
testcase_04 AC 62 ms
78,280 KB
testcase_05 AC 49 ms
72,672 KB
testcase_06 AC 47 ms
72,688 KB
testcase_07 AC 34 ms
52,544 KB
testcase_08 AC 34 ms
52,924 KB
testcase_09 AC 34 ms
53,164 KB
testcase_10 AC 38 ms
52,612 KB
testcase_11 AC 33 ms
52,212 KB
testcase_12 AC 34 ms
52,068 KB
testcase_13 AC 34 ms
52,408 KB
testcase_14 AC 61 ms
78,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda:sys.stdin.readline().rstrip()
def write(i,depth):
	if depth[i]!=-1:
		return
	write(par[i],depth)
	depth[i]=depth[par[i]]+1
mod=998244353
N=int(input())
par=[0]+[int(input())-1 for i in range(N-1)]
depth=[-1 for i in range(N)]
depth[0]=0
for i in range(1,N):
	write(i,depth)
ans=1
for i in depth:
	ans=(ans*max(i,1))%mod
print(ans)
0