結果

問題 No.1565 Union
ユーザー googol_S0googol_S0
提出日時 2021-06-26 13:46:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 716 ms / 2,000 ms
コード長 597 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 113,424 KB
最終ジャッジ日時 2024-04-30 19:53:16
合計ジャッジ時間 10,960 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,296 KB
testcase_01 AC 38 ms
53,632 KB
testcase_02 AC 40 ms
54,132 KB
testcase_03 AC 40 ms
53,388 KB
testcase_04 AC 40 ms
53,532 KB
testcase_05 AC 38 ms
53,224 KB
testcase_06 AC 39 ms
53,616 KB
testcase_07 AC 40 ms
54,256 KB
testcase_08 AC 41 ms
53,352 KB
testcase_09 AC 40 ms
54,556 KB
testcase_10 AC 235 ms
89,052 KB
testcase_11 AC 396 ms
99,972 KB
testcase_12 AC 387 ms
96,008 KB
testcase_13 AC 203 ms
84,104 KB
testcase_14 AC 489 ms
101,200 KB
testcase_15 AC 712 ms
113,164 KB
testcase_16 AC 418 ms
108,188 KB
testcase_17 AC 716 ms
113,364 KB
testcase_18 AC 698 ms
113,424 KB
testcase_19 AC 707 ms
113,152 KB
testcase_20 AC 254 ms
109,876 KB
testcase_21 AC 270 ms
110,188 KB
testcase_22 AC 263 ms
110,100 KB
testcase_23 AC 272 ms
110,196 KB
testcase_24 AC 275 ms
109,904 KB
testcase_25 AC 356 ms
110,580 KB
testcase_26 AC 334 ms
110,492 KB
testcase_27 AC 347 ms
110,452 KB
testcase_28 AC 338 ms
110,584 KB
testcase_29 AC 336 ms
110,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
from heapq import *
G=[[] for i in range(N)]
D=[0]*N
INF=10**17
def ijk(s):
  global D,INF,G
  for i in range(len(G)):
    D[i]=INF
  D[s]=0
  Q=[]
  heapify(Q)
  heappush(Q,(0,s))
  p,v,e=0,0,0
  while len(Q):
    p=heappop(Q)
    v=p[1]
    if D[v]<p[0]:
      continue
    for i in range(len(G[v])):
      e=G[v][i]
      if D[e[0]]>D[v]+e[1]:
        D[e[0]]=D[v]+e[1]
        heappush(Q,(D[e[0]],e[0]))

for i in range(M):
  a,b=map(int,input().split())
  a-=1
  b-=1
  G[a].append((b,1))
  G[b].append((a,1))
ijk(0)
if D[-1]<INF:
  print(D[-1])
else:
  print(-1)
0