結果
問題 | No.1565 Union |
ユーザー |
|
提出日時 | 2022-11-29 08:24:47 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 761 ms / 2,000 ms |
コード長 | 607 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 51,840 KB |
最終ジャッジ日時 | 2024-11-26 15:03:08 |
合計ジャッジ時間 | 13,604 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import sysfrom collections import dequeinput = sys.stdin.buffer.readlinedef solve(N, G):INF = 10 ** 9# bfsd = deque([0])dist = [INF] * Ndist[0] = 0while d:v = d.popleft()if v == N - 1:return dist[v]dx = dist[v] + 1for x in G[v]:if dist[x] == INF:d.append(x)dist[x] = dxreturn -1N, M = map(int, input().split())G = [[] for _ in range(N)]for _ in range(M):a, b = tuple(int(x) - 1 for x in input().split())G[a].append(b)G[b].append(a)print(solve(N, G))