結果

問題 No.1878 union-find の数え上げ
ユーザー chineristACchineristAC
提出日時 2022-03-18 22:06:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 89,828 KB
最終ジャッジ日時 2024-04-14 12:10:55
合計ジャッジ時間 2,175 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
83,520 KB
testcase_01 AC 118 ms
83,544 KB
testcase_02 AC 122 ms
83,548 KB
testcase_03 AC 116 ms
83,764 KB
testcase_04 AC 117 ms
83,452 KB
testcase_05 AC 84 ms
79,980 KB
testcase_06 AC 88 ms
80,116 KB
testcase_07 AC 45 ms
56,900 KB
testcase_08 AC 46 ms
57,524 KB
testcase_09 AC 46 ms
56,916 KB
testcase_10 AC 45 ms
57,340 KB
testcase_11 AC 45 ms
57,036 KB
testcase_12 AC 45 ms
56,116 KB
testcase_13 AC 45 ms
56,272 KB
testcase_14 AC 93 ms
89,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

mod = 998244353

N = int(input())
parent = [-1] + [int(input())-1 for i in range(N-1)]
edge = [[] for v in range(N)]
for i in range(1,N):
    edge[parent[i]].append(i)

depth = [0] * N
deq = deque([0])
while deq:
    v = deq.popleft()
    for nv in edge[v]:
        depth[nv] = depth[v] + 1
        deq.append(nv)

res = 1
for v in range(1,N):
    res *= depth[v]
    res %= mod

print(res)
0