結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー SalmonizeSalmonize
提出日時 2020-05-30 00:00:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,493 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 227,548 KB
最終ジャッジ日時 2023-09-30 08:33:44
合計ジャッジ時間 3,898 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,220 KB
testcase_01 AC 20 ms
8,208 KB
testcase_02 AC 18 ms
8,352 KB
testcase_03 AC 17 ms
8,284 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, heapq as hq

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def k_shortestPath(G, s, t, k):
    N = len(G)
    d = [10**18]*N
    d[t] = 0
    p = [-1]*N
    q = [(0, t, t)]
    ret = list()
    while q:
        wei, src, dst = hq.heappop(q)
        if p[dst] >= 0: continue
        p[dst] = src
        for fdst, fwei in G[dst]:
            if d[fdst] > wei + fwei:
                d[fdst] = wei + fwei
                hq.heappush(q, (d[fdst], dst, fdst))
    l = 0
    R = [(0, -1, s, 1<<s)]
    while R:
        wei, src, dst, bit = hq.heappop(R)
        if dst == t:
            ret.append(wei + d[s])
            l += 1
            if l == k:
                return ret
        for fdst, fwei in G[dst]:
            if not bit & (1 << fdst):
                hq.heappush(R, (wei + fwei - d[dst] + d[fdst], dst, fdst, bit | (1 << fdst)))
    return ret


def solve():
    n, m, k = nm()
    X, Y = nm()
    X -= 1; Y -= 1
    points = [tuple(nm()) for _ in range(n)]
    G = [list() for _ in range(n)]
    for _ in range(m):
        u, v = nm()
        u -= 1; v -= 1
        p, q = points[u]
        r, s = points[v]
        c = ((p - r)**2 + (q - s)**2) ** .5
        G[u].append((v, c))
        G[v].append((u, c))
    res = k_shortestPath(G, X, Y, k)
    res += [-1]*(k - len(res))
    print(*res, sep='\n')
    return

solve()
0