結果

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

ソースコード

diff #

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