結果

問題 No.3217 Shiki no Shiki
ユーザー YU Hirose
提出日時 2025-08-08 15:53:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 361 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 82,268 KB
実行使用メモリ 86,828 KB
最終ジャッジ日時 2025-08-08 15:53:10
合計ジャッジ時間 3,579 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
p = list(map(int, input().split()))
for i in range(n):
    p[i] -= 1
d = [0] * n
for i in range(n):
    if p[i] == -1:
        continue
    d[p[i]] += 1
s = [False] * n
for i in range(n):
    if d[i] == 0:
        if p[i] != -1 and p[p[i]] != -1:
            s[p[p[i]]] = True
cnt = 0
for i in range(n):
    if s[i]:
        cnt += 1
print(cnt)
0