結果
| 問題 |
No.1244 Black Segment
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-14 16:23:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 195 ms / 2,000 ms |
| コード長 | 402 bytes |
| コンパイル時間 | 278 ms |
| コンパイル使用メモリ | 82,576 KB |
| 実行使用メモリ | 89,508 KB |
| 最終ジャッジ日時 | 2025-10-14 16:23:20 |
| 合計ジャッジ時間 | 7,623 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
from collections import deque
n,m,a,b=map(int,input().split())
v=[[] for i in range(n+1)]
for i in range(m):
l,r=map(int,input().split())
l-=1
v[l].append(r);v[r].append(l)
f=deque([i for i in range(a)])
ans=[0 if i<a else -1 for i in range(n+1)]
s=-1
while f:
q=f.popleft()
if q>=b:
s=ans[q]
break
for i in v[q]:
if ans[i]==-1:
ans[i]=ans[q]+1
f.append(i)
print(s)