結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | hiragn |
提出日時 | 2022-12-13 14:09:54 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,021 bytes |
コンパイル時間 | 299 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 137,212 KB |
最終ジャッジ日時 | 2024-11-07 09:33:54 |
合計ジャッジ時間 | 88,944 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,136 KB |
testcase_01 | AC | 32 ms
11,136 KB |
testcase_02 | AC | 2,556 ms
124,920 KB |
testcase_03 | AC | 2,044 ms
110,976 KB |
testcase_04 | AC | 2,902 ms
136,956 KB |
testcase_05 | AC | 2,190 ms
122,880 KB |
testcase_06 | AC | 2,701 ms
125,428 KB |
testcase_07 | AC | 2,629 ms
122,876 KB |
testcase_08 | AC | 2,025 ms
111,564 KB |
testcase_09 | AC | 2,636 ms
119,724 KB |
testcase_10 | AC | 2,064 ms
111,744 KB |
testcase_11 | TLE | - |
testcase_12 | AC | 2,777 ms
129,096 KB |
testcase_13 | AC | 2,688 ms
126,384 KB |
testcase_14 | AC | 2,624 ms
118,032 KB |
testcase_15 | AC | 2,659 ms
118,272 KB |
testcase_16 | AC | 2,942 ms
137,200 KB |
testcase_17 | AC | 2,825 ms
129,772 KB |
testcase_18 | AC | 2,547 ms
118,360 KB |
testcase_19 | AC | 2,757 ms
126,624 KB |
testcase_20 | AC | 2,718 ms
126,032 KB |
testcase_21 | AC | 2,853 ms
126,372 KB |
testcase_22 | AC | 2,791 ms
130,140 KB |
testcase_23 | AC | 2,746 ms
126,656 KB |
testcase_24 | AC | 2,809 ms
126,828 KB |
testcase_25 | AC | 2,929 ms
134,068 KB |
testcase_26 | AC | 2,783 ms
124,328 KB |
testcase_27 | AC | 2,803 ms
126,728 KB |
testcase_28 | AC | 2,351 ms
119,132 KB |
testcase_29 | AC | 2,913 ms
137,212 KB |
testcase_30 | AC | 2,940 ms
133,052 KB |
testcase_31 | TLE | - |
testcase_32 | AC | 33 ms
11,136 KB |
testcase_33 | AC | 1,460 ms
120,288 KB |
testcase_34 | AC | 2,955 ms
129,720 KB |
ソースコード
from heapq import heappush, heappop class MinCostFlow: INF = 10 ** 18 def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap, cost): forward = [to, cap, cost, None] backward = forward[3] = [fr, 0, -cost, forward] self.G[fr].append(forward) self.G[to].append(backward) def flow(self, s, t, f): N = self.N; G = self.G INF = MinCostFlow.INF res = 0 H = [0] * N prv_v = [0] * N prv_e = [0] * N d0 = [INF] * N dist = [INF] * N while f: dist[:] = d0 dist[s] = 0 que = [(0, s)] while que: c, v = heappop(que) if dist[v] < c: continue r0 = dist[v] + H[v] for e in G[v]: w, cap, cost, _ = e if cap > 0 and r0 + cost - H[w] < dist[w]: dist[w] = r = r0 + cost - H[w] prv_v[w] = v prv_e[w] = e heappush(que, (r, w)) if dist[t] == INF: return None for i in range(N): H[i] += dist[i] d = f; v = t while v != s: d = min(d, prv_e[v][1]) v = prv_v[v] f -= d res += d * H[t] v = t while v != s: e = prv_e[v] e[1] -= d e[3][1] += d v = prv_v[v] return res def main(): n, m = map(int, input().split()) g = MinCostFlow(n) for _ in range(m): u, v, c, d = map(int, input().split()) u -= 1 v -= 1 g.add_edge(u, v, 1, c) g.add_edge(u, v, 1, d) g.add_edge(v, u, 1, c) g.add_edge(v, u, 1, d) print(g.flow(0, n - 1, 2)) if __name__ == "__main__": main()