結果

問題 No.3217 Shiki no Shiki
ユーザー tkykwtnb
提出日時 2025-08-01 21:40:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 464 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 100,484 KB
最終ジャッジ日時 2025-08-01 21:40:16
合計ジャッジ時間 4,138 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N=int(input())
P=list(map(int,input().split()))
G=[[]for _ in range(N+1)]
S=[1 for _ in range(N+1)]
for i,p in enumerate(P,1):
    G[i].append(p)
    S[p]=0
ans=0
for i in range(1,N+1):
    if S[i]==0:continue
    Q=deque([(i,0)])
    while Q:
        now,cnt=Q.popleft()
        if cnt==2:
            ans+=1
            continue
        for nxt in G[now]:
            if nxt==0:continue
            Q.append((nxt,cnt+1))
print(ans)
0