結果
| 問題 | No.1565 Union |
| コンテスト | |
| ユーザー |
wgrape
|
| 提出日時 | 2025-03-17 09:56:12 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 346 ms / 2,000 ms |
| コード長 | 509 bytes |
| 記録 | |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 95,848 KB |
| 実行使用メモリ | 109,952 KB |
| 最終ジャッジ日時 | 2026-07-07 05:10:06 |
| 合計ジャッジ時間 | 8,809 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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())
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
from collections import deque
q = deque([])
q.append([0, 0])
visited = [False] * N
visited[0] = True
while q:
v, c = q.popleft()
if v == N - 1:
print(c)
break
for child in G[v]:
if visited[child]:
continue
visited[child] = True
q.append([child, c + 1])
else:
print(-1)
wgrape