結果

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

ソースコード

diff #

N = int(input())
P = list(map(int, input().split()))
P = [p - 1 for p in P]

g = [list() for i in range(N)]
called = [False] * N
for i in range(N):
    if P[i] != -1:
        g[i].append(P[i])
        called[P[i]] = True

is_ss = [False] * N
for i in range(N):
    if not called[i] and P[i] != -1 and P[P[i]] != -1:
        v = P[P[i]]
        is_ss[v] = True
ans = sum(is_ss)
print(ans)
0