結果
問題 | No.654 Air E869120 |
ユーザー | zundamo-ti |
提出日時 | 2020-10-26 01:59:00 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 981 ms / 2,000 ms |
コード長 | 1,983 bytes |
コンパイル時間 | 341 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 75,264 KB |
最終ジャッジ日時 | 2024-07-21 21:11:32 |
合計ジャッジ時間 | 11,428 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,136 KB |
testcase_01 | AC | 30 ms
11,008 KB |
testcase_02 | AC | 31 ms
11,008 KB |
testcase_03 | AC | 31 ms
10,880 KB |
testcase_04 | AC | 31 ms
11,008 KB |
testcase_05 | AC | 31 ms
11,008 KB |
testcase_06 | AC | 31 ms
11,008 KB |
testcase_07 | AC | 31 ms
10,880 KB |
testcase_08 | AC | 31 ms
11,008 KB |
testcase_09 | AC | 30 ms
10,880 KB |
testcase_10 | AC | 981 ms
75,264 KB |
testcase_11 | AC | 656 ms
75,008 KB |
testcase_12 | AC | 788 ms
75,008 KB |
testcase_13 | AC | 865 ms
75,008 KB |
testcase_14 | AC | 604 ms
74,880 KB |
testcase_15 | AC | 704 ms
75,136 KB |
testcase_16 | AC | 333 ms
74,752 KB |
testcase_17 | AC | 342 ms
74,624 KB |
testcase_18 | AC | 314 ms
74,624 KB |
testcase_19 | AC | 333 ms
74,624 KB |
testcase_20 | AC | 255 ms
74,752 KB |
testcase_21 | AC | 261 ms
74,624 KB |
testcase_22 | AC | 236 ms
74,752 KB |
testcase_23 | AC | 245 ms
74,752 KB |
testcase_24 | AC | 249 ms
74,496 KB |
testcase_25 | AC | 234 ms
74,496 KB |
testcase_26 | AC | 238 ms
74,624 KB |
testcase_27 | AC | 228 ms
74,496 KB |
testcase_28 | AC | 232 ms
74,496 KB |
testcase_29 | AC | 227 ms
74,624 KB |
testcase_30 | AC | 225 ms
74,368 KB |
testcase_31 | AC | 224 ms
74,496 KB |
testcase_32 | AC | 222 ms
74,496 KB |
testcase_33 | AC | 224 ms
74,496 KB |
testcase_34 | AC | 223 ms
74,624 KB |
testcase_35 | AC | 30 ms
10,880 KB |
testcase_36 | AC | 30 ms
11,008 KB |
testcase_37 | AC | 30 ms
11,008 KB |
testcase_38 | AC | 30 ms
10,880 KB |
testcase_39 | AC | 32 ms
11,008 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)