結果
| 問題 |
No.1565 Union
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-12-03 01:05:59 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,177 ms / 2,000 ms |
| コード長 | 404 bytes |
| コンパイル時間 | 535 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 51,712 KB |
| 最終ジャッジ日時 | 2024-12-03 01:06:21 |
| 合計ジャッジ時間 | 21,279 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
from collections import deque
N,M=map(int,input().split())
E=[[] for i in range(N+1)]
DIS=[1<<30]*(N+1)
DIS[1]=0
Q=deque([1])
for i in range(M):
x,y=map(int,input().split())
E[x].append(y)
E[y].append(x)
while Q:
x=Q.popleft()
for to in E[x]:
if DIS[to]>DIS[x]+1:
DIS[to]=DIS[x]+1
Q.append(to)
if DIS[N]>N+10:
print(-1)
else:
print(DIS[N])
titia