結果
問題 |
No.3263 違法な散歩道
|
ユーザー |
![]() |
提出日時 | 2025-09-16 04:20:09 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 801 bytes |
コンパイル時間 | 546 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 102,296 KB |
最終ジャッジ日時 | 2025-09-16 04:20:19 |
合計ジャッジ時間 | 9,547 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 RE * 1 |
other | AC * 28 |
ソースコード
from collections import deque N,M=map(int,input().split()) E=[[] for i in range(N)] for i in range(M): x,y=map(int,input().split()) x-=1 y-=1 E[x].append(y) E[y].append(x) K=int(input()) A=list(map(int,input().split())) X=[0]*N for a in A: X[a-1]=1 DP=[[1<<60]*N for i in range(6)] DP[0][0]=0 Q=[(0,0)] Q=deque(Q) while Q: now,iwi=Q.popleft() for to in E[now]: if X[to]==0: if DP[0][to]>DP[iwi][now]+1: DP[0][to]=DP[iwi][now]+1 Q.append((to,0)) else: if iwi+1<5 and DP[iwi+1][to]>DP[iwi][now]+1: DP[iwi+1][to]=DP[iwi][now]+1 Q.append((to,iwi+1)) ANS=1<<60 for i in range(6): ANS=min(ANS,DP[i][N-1]) if ANS==1<<60: print(-1) else: print(ANS)