結果

問題 No.3810 Binary Shortest Path Query
コンテスト
ユーザー shotoyoo
提出日時 2026-11-20 22:38:10
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,801 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,308 ms
コンパイル使用メモリ 64,104 KB
実行使用メモリ 93,176 KB
最終ジャッジ日時 2026-11-20 22:38:27
合計ジャッジ時間 13,961 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys, random
input = lambda : sys.stdin.readline().rstrip()

write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO);
LI = lambda v=0: list(map(lambda i: int(i)-v, input().split())); II=lambda : int(input()); SI=lambda c0: [ord(c)-ord(c0) for c in input()]
def debug(_l_):
    for s in _l_.split():
        print(f"{s}={eval(s)}", end=" ")
    print()
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]

n,m,q = list(map(int, input().split()))
s = LI()
ns = [[] for _ in range(n)]
INF = 7*(10**18)
for i in range(1,m+1):
    u,v,w = LI()
    u -= 1
    v -= 1
    if i<90 and (1<<i)*w<INF:
        ns[u].append(((1<<i)*w,v))
        ns[v].append(((1<<i)*w,u))

### ダイクストラ dijkstra
_val = 1<<20
inf = INF
def to(d,u):
    return d*_val+u
def frm(val):
    return divmod(val,_val)
def dijkstra(start,ns):
    from heapq import heappop as hpp, heappush as hp
    n = len(ns)
    vals = {}
    h = [to(0, start)] # (距離, ノード番号)
    vals[start] = 0
    # order = []
    while h:
        val, u = frm(hpp(h))
        if val>vals[u]:
            continue
        # order.append(u)
        for d,v in ns[u]:
            if v not in vals or vals[v]>val+d:
                vals[v] = val+d
                hp(h, to(vals[v], v))
    return vals #, order

for i in range(q):
    a,b = LI(1)
    da = dijkstra(a,ns)
    db = dijkstra(b,ns)
    ba = bb = INF
    for u,val in da.items():
        ba = min(ba, val+s[u])
    for u,val in db.items():
            bb = min(bb, val+s[u])
    res = ba+bb
    if b in da:
        res = min(res, da[b])
    print(res)
0