結果
問題 | No.654 Air E869120 |
ユーザー | zundamo-ti |
提出日時 | 2020-10-26 01:59:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 334 ms / 2,000 ms |
コード長 | 1,983 bytes |
コンパイル時間 | 295 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 155,644 KB |
最終ジャッジ日時 | 2024-07-21 21:12:28 |
合計ジャッジ時間 | 7,038 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
54,732 KB |
testcase_01 | AC | 43 ms
55,108 KB |
testcase_02 | AC | 43 ms
55,144 KB |
testcase_03 | AC | 42 ms
54,928 KB |
testcase_04 | AC | 44 ms
54,660 KB |
testcase_05 | AC | 44 ms
55,764 KB |
testcase_06 | AC | 44 ms
55,864 KB |
testcase_07 | AC | 43 ms
55,404 KB |
testcase_08 | AC | 43 ms
54,804 KB |
testcase_09 | AC | 43 ms
54,836 KB |
testcase_10 | AC | 334 ms
155,644 KB |
testcase_11 | AC | 265 ms
153,012 KB |
testcase_12 | AC | 284 ms
154,084 KB |
testcase_13 | AC | 305 ms
154,036 KB |
testcase_14 | AC | 250 ms
153,128 KB |
testcase_15 | AC | 274 ms
154,948 KB |
testcase_16 | AC | 194 ms
148,712 KB |
testcase_17 | AC | 202 ms
148,188 KB |
testcase_18 | AC | 192 ms
148,448 KB |
testcase_19 | AC | 199 ms
148,792 KB |
testcase_20 | AC | 190 ms
149,720 KB |
testcase_21 | AC | 182 ms
149,472 KB |
testcase_22 | AC | 166 ms
149,024 KB |
testcase_23 | AC | 181 ms
149,076 KB |
testcase_24 | AC | 179 ms
148,948 KB |
testcase_25 | AC | 160 ms
149,220 KB |
testcase_26 | AC | 169 ms
149,432 KB |
testcase_27 | AC | 162 ms
149,400 KB |
testcase_28 | AC | 165 ms
149,268 KB |
testcase_29 | AC | 157 ms
148,232 KB |
testcase_30 | AC | 125 ms
128,688 KB |
testcase_31 | AC | 127 ms
128,728 KB |
testcase_32 | AC | 128 ms
128,728 KB |
testcase_33 | AC | 124 ms
128,716 KB |
testcase_34 | AC | 125 ms
128,504 KB |
testcase_35 | AC | 42 ms
55,548 KB |
testcase_36 | AC | 42 ms
55,324 KB |
testcase_37 | AC | 42 ms
54,432 KB |
testcase_38 | AC | 42 ms
55,536 KB |
testcase_39 | AC | 44 ms
55,444 KB |
ソースコード
from collections import deque INF = float('inf') class EDOMONDS_KARP(): def __init__(self, N, s, t): self.N = N; self.s = s; self.t = t self.cap = [[0]*N for _ in range(N)] self.link = [[] for _ in range(N)] def add_edge(self, u, v, c): self.cap[u][v] = c self.link[u].append(v) self.link[v].append(u) def max_flow(self): N = self.N; s = self.s; t = self.t f = 0 flow = [[0]*N for _ in range(N)] while True: m, prev = self.bfs(flow) if m == 0: break f += m v = t while v != s: u = prev[v] flow[u][v] += m flow[v][u] -=m v = u return (f, flow) def bfs(self, flow): N = self.N; s = self.s; t = self.t cap = self.cap link = self.link prev = [-1]*N; prev[s] = -2 m = [0]*N; m[s] = INF q = deque([s]) while q: u = q.popleft() for v in link[u]: if cap[u][v] - flow[u][v] > 0 and prev[v] == -1: prev[v] = u m[v] = min(m[u], cap[u][v] - flow[u][v]) if v != t: q.append(v) else: return (m[t], prev) return (0, prev) N, M, d = map(int, input().split()) S, T = 0, 2*M + 1 EK = EDOMONDS_KARP(2*M + 2, S, T) start = [[] for _ in range(N + 1)] stop = [[] for _ in range(N + 1)] for i in range(1, M + 1): u, v, p, q, w = map(int, input().split()) EK.add_edge(i, i + M, w) start[u].append((p, i)) stop[v].append((q, i + M)) for _, i in start[1]: EK.add_edge(S, i, INF) for _, i in stop[N]: EK.add_edge(i, T, INF) for v in range(1, N + 1): for q, i in stop[v]: for p, j in start[v]: if q + d <= p: EK.add_edge(i, j, INF) f, _ = EK.max_flow() print(f)