結果
| 問題 | No.1244 Black Segment |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-10-02 08:06:52 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 156 ms / 2,000 ms |
| コード長 | 485 bytes |
| 記録 | |
| コンパイル時間 | 296 ms |
| コンパイル使用メモリ | 85,440 KB |
| 実行使用メモリ | 186,484 KB |
| 最終ジャッジ日時 | 2026-04-02 19:47:45 |
| 合計ジャッジ時間 | 5,576 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
from collections import deque
N,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]=0
while D:
v=D.popleft()
for nv in G[v]:
if depth[nv]==-1:
depth[nv]=depth[v]+1
D.append(nv)
ans=10**9
for i in range(B,N+1):
if depth[i]!=-1:
ans=min(ans,depth[i])
if ans==10**9:
print(-1)
else:
print(ans)