結果
問題 | No.1565 Union |
ユーザー |
👑 ![]() |
提出日時 | 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 |
ソースコード
"""https://yukicoder.me/problems/no/1565テスト用s"""import sysfrom sys import stdin#重みのないグラフでの最短経路問題#隣接リストと始点を与えると始点からの距離のリスト & 親のリストを返すfrom collections import dequedef NC_Dij(lis,start):ret = [float("inf")] * len(lis)ret[start] = 0q = deque([start])while len(q) > 0:now = q.popleft()for nex in lis[now]:if ret[nex] > ret[now] + 1:ret[nex] = ret[now] + 1q.append(nex)return retN,M = map(int,stdin.readline().split())assert 2 <= N <= 200000assert 2 <= M <= 200000#lis = [ [] for i in range(N) ]for i in range(M):a,b = map(int,stdin.readline().split())assert a != bassert 1 <= a <= Nassert 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)