結果

問題 No.1565 Union
ユーザー 👑 SPD_9X2
提出日時 2021-06-26 13:22:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,060 bytes
コンパイル時間 496 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 76,576 KB
最終ジャッジ日時 2024-06-25 10:22:54
合計ジャッジ時間 4,334 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1565

テスト用s

"""

import sys
from sys import stdin
#重みのないグラフでの最短経路問題
#隣接リストと始点を与えると始点からの距離のリスト & 親のリストを返す
from collections import deque
def NC_Dij(lis,start):

    ret = [float("inf")] * len(lis)
    ret[start] = 0
    
    q = deque([start])

    while len(q) > 0:
        now = q.popleft()

        for nex in lis[now]:

            if ret[nex] > ret[now] + 1:
                ret[nex] = ret[now] + 1
                q.append(nex)

    return ret
N,M = map(int,stdin.readline().split())
assert 2 <= N <= 200000
assert 2 <= M <= 200000

#lis = [ [] for i in range(N) ]

for i in range(M):

    a,b = map(int,stdin.readline().split())
    assert a != b
    assert 1 <= a <= N
    assert 1 <= b <= N
    #a -= 1
    #b -= 1

    #if 0 <= a < N and 0 <= b < N:
    #    lis[a].append(b)
    #    lis[b].append(a)

#print ("a")
sys.exit()

dlis = NC_Dij(lis,0)

ans = dlis[-1]

print (ans if ans!=float("inf") else -1)
0