結果

問題 No.2604 Initial Motion
ユーザー titiatitia
提出日時 2024-01-13 00:36:40
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,805 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 99,716 KB
最終ジャッジ日時 2024-01-13 00:37:00
合計ジャッジ時間 18,574 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 45 ms
62,108 KB
testcase_03 AC 247 ms
77,064 KB
testcase_04 AC 241 ms
77,216 KB
testcase_05 AC 244 ms
77,688 KB
testcase_06 AC 241 ms
77,444 KB
testcase_07 AC 248 ms
77,632 KB
testcase_08 AC 241 ms
77,260 KB
testcase_09 AC 254 ms
77,464 KB
testcase_10 AC 242 ms
77,168 KB
testcase_11 AC 252 ms
77,784 KB
testcase_12 AC 252 ms
77,824 KB
testcase_13 TLE -
testcase_14 AC 2,408 ms
83,792 KB
testcase_15 AC 1,543 ms
81,692 KB
testcase_16 TLE -
testcase_17 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from heapq import heappop,heappush

K,N,M=map(int,input().split())

A=list(map(int,input().split()))
B=list(map(int,input().split()))

                
# 最小費用流

# まず、グラフ作り

V=N+2 # 頂点数

EDGE=[[] for i in range(V+1)]

def add_edge(u,v,k,c): # u→vに容量k, 費用cの辺を張る
    X=[v,c,k,[]]
    Y=X[3]=[u,-c,0,X]

    EDGE[u].append(X)
    EDGE[v].append(Y)

start=V-2
goal=V-1

C=[0]*N
for a in A:
    C[a-1]+=1

for i in range(N):
    if C[i]==0:
        continue
    add_edge(start,i,C[i],0)

for i in range(N):
    add_edge(i,goal,B[i],0)

for i in range(M):
    u,v,d=map(int,input().split())
    u-=1
    v-=1
    add_edge(u,v,K,d)
    add_edge(v,u,K,d)

Flowed_edge=[[] for i in range(V)]
BACK=[-1]*(V)
P=[0]*(V) # ポテンシャル
LA=0 # 最終的な答え

for fl in range(K):
    ANS=[1<<62]*V
    Q=[start] # 一次元化している。(time<<20)+node
    ANS[start]=0

    while Q: # ここはダイクストラ
        x = heappop(Q)
        time = x>>20
        fr = x - (time<<20)
        if time != ANS[fr]:
            continue

        for to,cost,vol,f_edge in EDGE[fr]:        
            if vol>0 and ANS[to]>ANS[fr]+cost+P[fr]-P[to]:# ポテンシャルによりコストを調整        
                ANS[to]=ANS[fr]+cost+P[fr]-P[to]
                BACK[to]=fr
                Flowed_edge[to]=f_edge
                heappush(Q,((ANS[to])<<20)+to)

    LA+=ANS[goal]+P[goal]

    P=[P[i]+ANS[i] for i in range(V)] # ポテンシャルを調整
 
    NOW=goal
    while NOW!=start:
        f_edge=Flowed_edge[NOW]
        f_edge[3][2]-=1 # 流した分の容量を削る
        f_edge[2]+=1 # 逆向きに+1する

        NOW=BACK[NOW]

print(LA)


0