結果
問題 | No.1244 Black Segment |
ユーザー |
|
提出日時 | 2021-10-02 08:06:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 266 ms / 2,000 ms |
コード長 | 485 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 88,960 KB |
最終ジャッジ日時 | 2024-07-20 02:30:14 |
合計ジャッジ時間 | 8,822 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
from collections import dequeN,M,A,B=map(int,input().split())G=[[] for _ in range(N+1)]for _ in range(M):l,r=map(int,input().split())G[l-1].append(r)G[r].append(l-1)D=deque()depth=[-1]*(N+1)for i in range(A):D.append(i)depth[i]=0while D:v=D.popleft()for nv in G[v]:if depth[nv]==-1:depth[nv]=depth[v]+1D.append(nv)ans=10**9for i in range(B,N+1):if depth[i]!=-1:ans=min(ans,depth[i])if ans==10**9:print(-1)else:print(ans)