結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | roaris |
提出日時 | 2020-11-28 02:18:42 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,928 bytes |
コンパイル時間 | 649 ms |
コンパイル使用メモリ | 81,980 KB |
実行使用メモリ | 129,040 KB |
最終ジャッジ日時 | 2024-09-12 21:48:01 |
合計ジャッジ時間 | 11,576 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,392 KB |
testcase_01 | AC | 36 ms
52,816 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 37 ms
52,748 KB |
testcase_33 | AC | 286 ms
126,204 KB |
testcase_34 | WA | - |
ソースコード
import sys input = sys.stdin.readline class Mincostflow: def __init__(self, N): self.N = N self.G = [[] for _ in range(N)] def add_edge(self, u, v, cap, cost): self.G[u].append([v, cap, cost, len(self.G[v])]) self.G[v].append([u, 0, -cost, len(self.G[u])-1]) def min_cost_flow(self, s, t, f): res = 0 while f>0: dist = [10**18]*self.N dist[s] = 0 prev_v = [-1]*self.N prev_e = [-1]*self.N update = True while update: update = False for v in range(self.N): if dist[v]==10**18: continue for i in range(len(self.G[v])): nv, cap, cost, _ = self.G[v][i] if cap>0 and dist[nv]>dist[v]+cost: dist[nv] = dist[v]+cost prev_v[nv] = v prev_e[nv] = i update = True if dist[t]==10**18: return -1 d = f v = t while v!=s: d = min(d, self.G[prev_v[v]][prev_e[v]][1]) v = prev_v[v] f -= d res += d*dist[t] v = t while v!=s: self.G[prev_v[v]][prev_e[v]][1] -= d rev = self.G[prev_v[v]][prev_e[v]][3] self.G[v][rev][1] += d v = prev_v[v] return res N, M = map(int, input().split()) mcf = Mincostflow(N) for _ in range(M): u, v, c, d = map(int, input().split()) mcf.add_edge(u-1, v-1, 1, c) mcf.add_edge(u-1, v-1, 1, d) print(mcf.min_cost_flow(0, N-1, 2))