結果
問題 | No.1565 Union |
ユーザー |
![]() |
提出日時 | 2021-06-26 13:33:45 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 969 ms / 2,000 ms |
コード長 | 1,636 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 53,760 KB |
最終ジャッジ日時 | 2024-12-20 18:53:57 |
合計ジャッジ時間 | 15,713 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import bisect,collections,copy,heapq,itertools,math,string,sys,queue,timefrom typing import Union, ValuesViewinput = 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);returnstart_time=time.time()def nt(): print(time.time()-start_time);returndef chmax(a: list, b: list) -> bool:assert len(a) == len(b) == 1, "1要素のlistを指定してください"if a[0] < b[0]:a[0] = b[0]return Truereturn Falsedef chmin(a: list, b: list) -> bool:assert len(a) == len(b) == 1, "1要素のlistを指定してください"if a[0] > b[0]:a[0] = b[0]return Truereturn Falsedef combinations_count(n, r):return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))def Base_n_to_10(X,n):out = 0for i in range(1,len(str(X))+1):out += int(X[-i])*(n**(i-1))return out#int outragen=rangeINF=10**20MOD=10**9+7from 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]=0while len(q):to=q.popleft()for i in li[to]:if dis[i]==10**19:dis[i]=dis[to]+1q.append(i)print(dis[n-1] if dis[n-1]!=10**19 else -1)