結果
問題 | No.654 Air E869120 |
ユーザー | 👑 rin204 |
提出日時 | 2022-11-03 00:30:06 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,316 bytes |
コンパイル時間 | 189 ms |
コンパイル使用メモリ | 82,500 KB |
実行使用メモリ | 81,024 KB |
最終ジャッジ日時 | 2024-07-17 12:06:01 |
合計ジャッジ時間 | 6,333 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
56,628 KB |
testcase_01 | AC | 45 ms
55,280 KB |
testcase_02 | AC | 42 ms
56,204 KB |
testcase_03 | AC | 47 ms
55,036 KB |
testcase_04 | AC | 42 ms
55,412 KB |
testcase_05 | AC | 42 ms
55,396 KB |
testcase_06 | AC | 48 ms
61,696 KB |
testcase_07 | AC | 43 ms
56,384 KB |
testcase_08 | AC | 43 ms
55,844 KB |
testcase_09 | AC | 42 ms
55,344 KB |
testcase_10 | AC | 312 ms
80,260 KB |
testcase_11 | AC | 277 ms
81,024 KB |
testcase_12 | AC | 243 ms
79,380 KB |
testcase_13 | AC | 246 ms
80,140 KB |
testcase_14 | AC | 231 ms
79,308 KB |
testcase_15 | AC | 259 ms
80,220 KB |
testcase_16 | AC | 250 ms
79,732 KB |
testcase_17 | AC | 273 ms
80,492 KB |
testcase_18 | AC | 228 ms
79,820 KB |
testcase_19 | AC | 269 ms
80,960 KB |
testcase_20 | AC | 161 ms
78,908 KB |
testcase_21 | AC | 175 ms
79,900 KB |
testcase_22 | AC | 109 ms
78,204 KB |
testcase_23 | AC | 140 ms
78,928 KB |
testcase_24 | AC | 158 ms
78,396 KB |
testcase_25 | AC | 104 ms
78,128 KB |
testcase_26 | AC | 116 ms
78,260 KB |
testcase_27 | AC | 98 ms
77,876 KB |
testcase_28 | AC | 122 ms
78,492 KB |
testcase_29 | AC | 96 ms
77,708 KB |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | AC | 46 ms
55,248 KB |
testcase_36 | AC | 41 ms
56,180 KB |
testcase_37 | AC | 41 ms
55,484 KB |
testcase_38 | AC | 42 ms
54,616 KB |
testcase_39 | AC | 43 ms
55,152 KB |
ソースコード
from collections import deque import sys sys.setrecursionlimit(10 ** 9) class Dinic: def __init__(self, n): self.n = n self.links = [[] for _ in range(n)] self.depth = None self.progress = None def add_link(self, _from, to, cap): self.links[_from].append([cap, to, len(self.links[to])]) self.links[to].append([0, _from, len(self.links[_from]) - 1]) def bfs(self, s): depth = [-1] * self.n depth[s] = 0 q = deque([s]) while q: v = q.popleft() for cap, to, rev in self.links[v]: if cap > 0 and depth[to] < 0: depth[to] = depth[v] + 1 q.append(to) self.depth = depth def dfs(self, v, t, flow): if v == t: return flow links_v = self.links[v] for i in range(self.progress[v], len(links_v)): self.progress[v] = i cap, to, rev = link = links_v[i] if cap == 0 or self.depth[v] >= self.depth[to]: continue d = self.dfs(to, t, min(flow, cap)) if d == 0: continue link[0] -= d self.links[to][rev][0] += d return d return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.depth[t] < 0: return flow self.progress = [0] * self.n current_flow = self.dfs(s, t, float('inf')) while current_flow > 0: flow += current_flow current_flow = self.dfs(s, t, float('inf')) n, m, d = map(int, input().split()) Q = [[] for _ in range(n)] Q[0].append(-1) Q[-1].append(1 << 60) E = [] for _ in range(m): u, v, p, q, w = map(int, input().split()) q += d u -= 1 v -= 1 E.append((u, v, p, q, w)) Q[u].append(p) Q[v].append(q) dic = {} ind = 0 for i in range(n): Q[i].sort() for j in Q[i]: dic[(i, j)] = ind ind += 1 G = Dinic(ind) for u, v, p, q, w in E: G.add_link(dic[(u, p)], dic[(v, q)], w) for i in range(n): b = dic[(i, Q[i][0])] for j in Q[i][1:]: c = dic[(i, j)] G.add_link(b, c, 1 << 60) b = c ans = G.max_flow(0, ind - 1) print(ans)