結果

問題 No.2604 Initial Motion
ユーザー titiatitia
提出日時 2024-01-13 00:11:09
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,836 bytes
コンパイル時間 3,576 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 93,684 KB
最終ジャッジ日時 2024-01-13 00:12:23
合計ジャッジ時間 20,813 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 45 ms
62,108 KB
testcase_03 AC 258 ms
77,060 KB
testcase_04 AC 234 ms
77,216 KB
testcase_05 AC 269 ms
77,684 KB
testcase_06 AC 238 ms
77,444 KB
testcase_07 AC 259 ms
77,628 KB
testcase_08 AC 231 ms
77,256 KB
testcase_09 AC 280 ms
77,464 KB
testcase_10 AC 235 ms
77,172 KB
testcase_11 AC 237 ms
77,800 KB
testcase_12 AC 239 ms
77,812 KB
testcase_13 TLE -
testcase_14 AC 2,261 ms
83,788 KB
testcase_15 AC 1,456 ms
81,684 KB
testcase_16 AC 2,734 ms
87,376 KB
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 2,454 ms
83,856 KB
testcase_22 TLE -
testcase_23 AC 2,433 ms
84,528 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 2,587 ms
85,936 KB
testcase_27 AC 2,209 ms
82,476 KB
testcase_28 AC 2,604 ms
85,440 KB
testcase_29 TLE -
testcase_30 AC 2,409 ms
83,136 KB
testcase_31 AC 2,855 ms
86,044 KB
testcase_32 AC 2,571 ms
84,720 KB
testcase_33 AC 758 ms
79,708 KB
testcase_34 AC 2,038 ms
87,008 KB
testcase_35 AC 1,903 ms
87,464 KB
testcase_36 AC 2,196 ms
87,124 KB
testcase_37 AC 1,052 ms
81,412 KB
testcase_38 AC 89 ms
76,240 KB
testcase_39 AC 97 ms
76,288 KB
testcase_40 AC 1,664 ms
85,732 KB
testcase_41 AC 1,687 ms
85,604 KB
権限があれば一括ダウンロードができます

ソースコード

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,1<<61,d)
    add_edge(v,u,1<<61,d)
    
    
#print(EDGE)

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