結果
問題 |
No.3217 Shiki no Shiki
|
ユーザー |
|
提出日時 | 2025-08-15 19:37:33 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 544 bytes |
コンパイル時間 | 482 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 111,336 KB |
最終ジャッジ日時 | 2025-08-15 19:37:38 |
合計ジャッジ時間 | 4,960 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 WA * 20 |
ソースコード
from collections import deque N=int(input()) P=[0]+list(map(int,input().split())) G=[set() for _ in range(N+1)] for i,p in enumerate(P): if p!=0:G[p].add(i) ans=0 for i,g in enumerate(G[1:],1): if P[i]!=0:continue for nxt in g: Q=deque([({i,nxt},nxt)]) while Q: grp,nxt=Q.popleft() if len(G[nxt])==0: if len(grp)>=3:ans+=1 continue for nxt2 in G[nxt]: if nxt2 not in grp: Q.append((grp|{nxt2},nxt2)) print(ans)