結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー mkawa2mkawa2
提出日時 2023-07-26 22:36:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,739 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-14 12:01:11
合計ジャッジ時間 19,425 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 31 ms
11,008 KB
testcase_07 AC 40 ms
11,136 KB
testcase_08 AC 40 ms
11,264 KB
testcase_09 AC 57 ms
11,520 KB
testcase_10 AC 45 ms
11,264 KB
testcase_11 AC 65 ms
11,648 KB
testcase_12 AC 52 ms
11,520 KB
testcase_13 AC 61 ms
11,648 KB
testcase_14 AC 35 ms
11,136 KB
testcase_15 AC 45 ms
11,392 KB
testcase_16 AC 125 ms
11,264 KB
testcase_17 AC 38 ms
11,136 KB
testcase_18 AC 38 ms
11,008 KB
testcase_19 AC 54 ms
11,392 KB
testcase_20 AC 34 ms
11,008 KB
testcase_21 AC 48 ms
11,392 KB
testcase_22 AC 31 ms
10,880 KB
testcase_23 AC 32 ms
11,008 KB
testcase_24 AC 31 ms
11,008 KB
testcase_25 AC 30 ms
10,880 KB
testcase_26 AC 31 ms
10,880 KB
testcase_27 AC 31 ms
10,880 KB
testcase_28 AC 37 ms
11,136 KB
testcase_29 AC 1,138 ms
11,776 KB
testcase_30 AC 33 ms
10,880 KB
testcase_31 AC 206 ms
11,136 KB
testcase_32 AC 31 ms
11,008 KB
testcase_33 AC 1,336 ms
11,776 KB
testcase_34 AC 615 ms
11,520 KB
testcase_35 AC 36 ms
11,008 KB
testcase_36 AC 52 ms
11,008 KB
testcase_37 AC 39 ms
10,880 KB
testcase_38 AC 39 ms
11,008 KB
testcase_39 AC 34 ms
11,008 KB
testcase_40 AC 29 ms
11,008 KB
testcase_41 AC 31 ms
10,880 KB
testcase_42 AC 30 ms
10,752 KB
testcase_43 AC 56 ms
11,520 KB
testcase_44 AC 46 ms
11,264 KB
testcase_45 AC 107 ms
11,904 KB
testcase_46 AC 268 ms
11,136 KB
testcase_47 AC 998 ms
11,776 KB
testcase_48 AC 139 ms
11,520 KB
testcase_49 AC 126 ms
11,008 KB
testcase_50 AC 31 ms
11,008 KB
testcase_51 AC 31 ms
11,008 KB
testcase_52 AC 48 ms
11,136 KB
testcase_53 AC 85 ms
11,136 KB
testcase_54 AC 1,739 ms
11,776 KB
testcase_55 AC 1,704 ms
11,776 KB
testcase_56 AC 1,707 ms
11,648 KB
testcase_57 AC 1,634 ms
12,032 KB
testcase_58 AC 1,621 ms
11,904 KB
testcase_59 AC 1,634 ms
11,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

inf = (1 << 63)-1

from heapq import *

t=int(input())
n,m=map(int,input().split())
to=[[] for _ in range(n)]
uvw=[]
for i in range(m):
    u,v,w=map(int,input().split())
    u,v=u-1,v-1
    to[u].append((v,w,i))
    if t==0:
        to[v].append((u,w,i))
    uvw.append((u,v,w))

def solve(s,g,lim):
    dd=[inf]*n
    hp=[]
    heappush(hp,(0,s))
    dd[s]=0
    while hp:
        d,u=heappop(hp)
        if u==g:return d
        if d>dd[u]:continue
        for v,w,i in to[u]:
            if fin[i]:continue
            if dd[v]<=d+w or d+w>=lim:continue
            dd[v]=d+w
            heappush(hp,(d+w,v))
    return inf

fin=[False]*m
ans=inf
for i,(u,v,w) in enumerate(uvw):
    if fin[i]:continue
    fin[i]=True
    ret=solve(v,u,ans-w)+w
    if ret<ans:ans=ret

if ans==inf:print(-1)
else:print(ans)
0