結果

問題 No.1565 Union
ユーザー mono_0812mono_0812
提出日時 2021-06-26 13:33:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 959 ms / 2,000 ms
コード長 1,636 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 53,760 KB
最終ジャッジ日時 2024-05-23 16:33:47
合計ジャッジ時間 15,845 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
12,672 KB
testcase_01 AC 46 ms
12,672 KB
testcase_02 AC 47 ms
12,672 KB
testcase_03 AC 47 ms
12,544 KB
testcase_04 AC 47 ms
12,800 KB
testcase_05 AC 47 ms
12,800 KB
testcase_06 AC 46 ms
12,544 KB
testcase_07 AC 47 ms
12,672 KB
testcase_08 AC 47 ms
12,544 KB
testcase_09 AC 47 ms
12,672 KB
testcase_10 AC 302 ms
23,040 KB
testcase_11 AC 510 ms
37,376 KB
testcase_12 AC 531 ms
30,592 KB
testcase_13 AC 187 ms
19,968 KB
testcase_14 AC 627 ms
35,968 KB
testcase_15 AC 949 ms
46,976 KB
testcase_16 AC 679 ms
46,848 KB
testcase_17 AC 947 ms
46,720 KB
testcase_18 AC 959 ms
46,848 KB
testcase_19 AC 952 ms
46,848 KB
testcase_20 AC 619 ms
53,504 KB
testcase_21 AC 620 ms
53,632 KB
testcase_22 AC 609 ms
53,632 KB
testcase_23 AC 618 ms
53,760 KB
testcase_24 AC 628 ms
53,632 KB
testcase_25 AC 652 ms
53,504 KB
testcase_26 AC 647 ms
53,632 KB
testcase_27 AC 651 ms
53,632 KB
testcase_28 AC 647 ms
53,760 KB
testcase_29 AC 640 ms
53,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect,collections,copy,heapq,itertools,math,string,sys,queue,time
from typing import Union, ValuesView
input = lambda: sys.stdin.readline().rstrip()
def I(): return input()
def IS(): return input().split()
def II(): return int(input())
def IIS(): return map(int,input().split())
def LIIS(): return list(map(int,input().split()))
def debug(*args): print(*args) if len(args)>0 else print(False);return
start_time=time.time()
def nt(): print(time.time()-start_time);return
def chmax(a: list, b: list) -> bool:
     assert len(a) == len(b) == 1, "1要素のlistを指定してください"
     if a[0] < b[0]:
         a[0] = b[0]
         return True
     return False
def chmin(a: list, b: list) -> bool:
    assert len(a) == len(b) == 1, "1要素のlistを指定してください"
    if a[0] > b[0]:
        a[0] = b[0]
        return True
    return False
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def Base_n_to_10(X,n):
    out = 0
    for i in range(1,len(str(X))+1):
        out += int(X[-i])*(n**(i-1))
    return out#int out
ragen=range
INF=10**20
MOD=10**9+7
from decimal import Decimal as d, DefaultContext
##############################################################################
n,m=IIS()
li=[[] for i in range(n)]
for i in range(m):
    a,b=IIS()
    li[a-1].append(b-1)
    li[b-1].append(a-1)
q=collections.deque()
q.append(0)
dis=[10**19 for i in range(n)]
dis[0]=0
while len(q):
    to=q.popleft()
    for i in li[to]:
        if dis[i]==10**19:
            dis[i]=dis[to]+1
            q.append(i)
print(dis[n-1] if dis[n-1]!=10**19 else -1)
0