結果
| 問題 | No.1878 union-find の数え上げ |
| コンテスト | |
| ユーザー |
wolgnik
|
| 提出日時 | 2022-03-18 21:47:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 448 bytes |
| コンパイル時間 | 210 ms |
| コンパイル使用メモリ | 82,468 KB |
| 実行使用メモリ | 89,616 KB |
| 最終ジャッジ日時 | 2024-10-03 09:27:06 |
| 合計ジャッジ時間 | 1,954 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 8 |
ソースコード
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)
wolgnik