結果

問題 No.1565 Union
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-06-26 13:22:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,060 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 77,728 KB
最終ジャッジ日時 2023-09-07 16:28:14
合計ジャッジ時間 6,010 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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