結果
| 問題 |
No.3263 違法な散歩道
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-06 15:58:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 710 bytes |
| コンパイル時間 | 411 ms |
| コンパイル使用メモリ | 82,772 KB |
| 実行使用メモリ | 95,936 KB |
| 最終ジャッジ日時 | 2025-09-06 15:58:15 |
| 合計ジャッジ時間 | 5,981 ms |
|
ジャッジサーバーID (参考情報) |
judge / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 WA * 2 TLE * 1 -- * 19 |
ソースコード
from collections import deque
N,M=map(int,input().split())
G=[[] for _ in range(N+1)]
for _ in range(M):
U,V=map(int,input().split())
G[U].append(V)
G[V].append(U)
K=int(input())
A=set()
if K:A=set(map(int,input().split()))
vis=[5 for _ in range(N+1)]
Q=deque()
Q.append((1,0,0))
while Q:
now,step,cnt=Q.popleft()
if now not in A:
cnt=0
vis[now]=cnt
if now==N:
exit(print(step))
for nxt in G[now]:
if cnt==4:
if nxt in A:continue
else:
if cnt+1>=vis[nxt]:continue
Q.append((nxt,step+1,cnt+1))
else:
if cnt+1>=vis[nxt]:continue
Q.append((nxt,step+1,cnt+1))
print(-1)