結果
| 問題 | No.1565 Union |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-26 13:10:35 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 343 ms / 2,000 ms |
| + 469µs | |
| コード長 | 407 bytes |
| 記録 | |
| コンパイル時間 | 243 ms |
| コンパイル使用メモリ | 96,356 KB |
| 実行使用メモリ | 109,056 KB |
| 最終ジャッジ日時 | 2026-07-25 14:31:43 |
| 合計ジャッジ時間 | 7,828 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
n, m = map(int, input().split())
G = [[] for i in range(n)]
for _ in range(m):
a, b = map(int, input().split())
a -= 1; b -= 1
G[a].append(b)
G[b].append(a)
from collections import deque
Q = deque([0])
dist = [-1] * n
dist[0] = 0
while Q:
now = Q.popleft()
for nex in G[now]:
if dist[nex] == -1:
dist[nex] = dist[now] + 1
Q.append(nex)
print(dist[-1])