結果
問題 | No.654 Air E869120 |
ユーザー | marroncastle |
提出日時 | 2020-09-29 08:59:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,232 ms / 2,000 ms |
コード長 | 1,472 bytes |
コンパイル時間 | 152 ms |
コンパイル使用メモリ | 82,228 KB |
実行使用メモリ | 87,940 KB |
最終ジャッジ日時 | 2024-07-03 13:41:38 |
合計ジャッジ時間 | 8,170 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
54,736 KB |
testcase_01 | AC | 40 ms
54,532 KB |
testcase_02 | AC | 39 ms
53,684 KB |
testcase_03 | AC | 39 ms
52,680 KB |
testcase_04 | AC | 39 ms
53,812 KB |
testcase_05 | AC | 39 ms
53,696 KB |
testcase_06 | AC | 39 ms
53,564 KB |
testcase_07 | AC | 39 ms
53,564 KB |
testcase_08 | AC | 39 ms
53,108 KB |
testcase_09 | AC | 39 ms
53,092 KB |
testcase_10 | AC | 1,232 ms
87,940 KB |
testcase_11 | AC | 536 ms
84,104 KB |
testcase_12 | AC | 859 ms
85,004 KB |
testcase_13 | AC | 891 ms
84,900 KB |
testcase_14 | AC | 326 ms
83,520 KB |
testcase_15 | AC | 439 ms
85,416 KB |
testcase_16 | AC | 143 ms
80,156 KB |
testcase_17 | AC | 191 ms
80,380 KB |
testcase_18 | AC | 136 ms
79,992 KB |
testcase_19 | AC | 196 ms
80,184 KB |
testcase_20 | AC | 97 ms
78,256 KB |
testcase_21 | AC | 96 ms
78,408 KB |
testcase_22 | AC | 66 ms
70,016 KB |
testcase_23 | AC | 89 ms
78,500 KB |
testcase_24 | AC | 97 ms
78,324 KB |
testcase_25 | AC | 66 ms
69,560 KB |
testcase_26 | AC | 75 ms
73,936 KB |
testcase_27 | AC | 69 ms
70,844 KB |
testcase_28 | AC | 75 ms
73,428 KB |
testcase_29 | AC | 60 ms
66,756 KB |
testcase_30 | AC | 55 ms
65,060 KB |
testcase_31 | AC | 55 ms
63,524 KB |
testcase_32 | AC | 57 ms
65,808 KB |
testcase_33 | AC | 55 ms
64,220 KB |
testcase_34 | AC | 54 ms
63,540 KB |
testcase_35 | AC | 38 ms
52,808 KB |
testcase_36 | AC | 38 ms
52,396 KB |
testcase_37 | AC | 38 ms
53,260 KB |
testcase_38 | AC | 37 ms
53,204 KB |
testcase_39 | AC | 45 ms
61,476 KB |
ソースコード
# Ford-Fulkerson algorithm class FordFulkerson: def __init__(self, N): self.N = N self.edge = [[] for i in range(N)] def add_edge(self, fr, to, cap): forward = [to, cap, None] forward[2] = backward = [fr, 0, forward] self.edge[fr].append(forward) self.edge[to].append(backward) def add_multi_edge(self, v1, v2, cap1, cap2): edge1 = [v2, cap1, None] edge1[2] = edge2 = [v1, cap2, edge1] self.edge[v1].append(edge1) self.edge[v2].append(edge2) def dfs(self, v, t, f): if v == t: return f used = self.used used[v] = 1 for e in self.edge[v]: w, cap, rev = e if cap and not used[w]: d = self.dfs(w, t, min(f, cap)) if d: e[1] -= d rev[1] += d return d return 0 def flow(self, s, t): flow = 0 f = INF = 10**9 + 7 N = self.N while f: self.used = [0]*N f = self.dfs(s, t, INF) flow += f return flow import sys readline = sys.stdin.readline INF = 10**18 N, M, d = map(int, readline().split()) ff = FordFulkerson(2*M+2) fr = [0]*M to = [0]*M for i in range(M): u, v, p, q, w = map(int, readline().split()) ff.add_edge(1+i, 1+M+i, w) fr[i] = (u,p) to[i] = (v,q+d) if u==1: ff.add_edge(0,1+i,INF) if v==N: ff.add_edge(1+M+i,2*M+1,INF) for i,(v,q) in enumerate(to): for j,(u,p) in enumerate(fr): if v==u and q<=p: ff.add_edge(1+M+i,1+j,INF) ans = ff.flow(0, 2*M+1) print(ans)