結果

問題 No.1565 Union
ユーザー O2MTO2MT
提出日時 2021-07-26 16:45:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 430 bytes
コンパイル時間 1,249 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 99,808 KB
最終ジャッジ日時 2023-09-29 13:28:59
合計ジャッジ時間 8,367 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,740 KB
testcase_01 AC 94 ms
71,580 KB
testcase_02 AC 93 ms
71,388 KB
testcase_03 AC 93 ms
71,648 KB
testcase_04 AC 94 ms
71,400 KB
testcase_05 AC 91 ms
71,868 KB
testcase_06 AC 94 ms
71,584 KB
testcase_07 AC 93 ms
71,844 KB
testcase_08 AC 90 ms
71,644 KB
testcase_09 AC 94 ms
71,612 KB
testcase_10 AC 226 ms
83,288 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N,M = map(int,input().split())
l = [[] for _ in range(N)]
for _ in range(M):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  l[a].append(b)
  l[b].append(a)
INF = 10**18
visited = [INF]*N
que = deque([(0,0)])
while que:
  i,c = que.pop()
  for j in l[i]:
    if c+1 < visited[j]:
      que.append((j,c+1))
      visited[j] = c+1

ans = -1
if visited[N-1] != INF:
  ans = visited[N-1]
print(ans)
0