結果
問題 | No.654 Air E869120 |
ユーザー | AEn |
提出日時 | 2022-11-03 16:11:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,762 bytes |
コンパイル時間 | 1,157 ms |
コンパイル使用メモリ | 86,888 KB |
実行使用メモリ | 82,012 KB |
最終ジャッジ日時 | 2023-09-25 00:59:06 |
合計ジャッジ時間 | 8,481 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
72,332 KB |
testcase_01 | WA | - |
testcase_02 | AC | 92 ms
71,732 KB |
testcase_03 | WA | - |
testcase_04 | AC | 95 ms
71,948 KB |
testcase_05 | AC | 94 ms
71,824 KB |
testcase_06 | RE | - |
testcase_07 | AC | 94 ms
72,440 KB |
testcase_08 | WA | - |
testcase_09 | AC | 92 ms
71,896 KB |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | AC | 224 ms
80,420 KB |
testcase_17 | AC | 241 ms
80,448 KB |
testcase_18 | AC | 231 ms
80,408 KB |
testcase_19 | AC | 241 ms
80,228 KB |
testcase_20 | AC | 187 ms
80,044 KB |
testcase_21 | AC | 193 ms
79,936 KB |
testcase_22 | AC | 168 ms
79,804 KB |
testcase_23 | AC | 173 ms
80,036 KB |
testcase_24 | AC | 191 ms
79,976 KB |
testcase_25 | AC | 152 ms
79,780 KB |
testcase_26 | AC | 175 ms
80,016 KB |
testcase_27 | AC | 151 ms
79,888 KB |
testcase_28 | AC | 160 ms
80,092 KB |
testcase_29 | AC | 143 ms
79,724 KB |
testcase_30 | AC | 129 ms
78,020 KB |
testcase_31 | AC | 133 ms
78,008 KB |
testcase_32 | AC | 130 ms
77,972 KB |
testcase_33 | AC | 130 ms
77,988 KB |
testcase_34 | AC | 134 ms
78,132 KB |
testcase_35 | AC | 94 ms
71,896 KB |
testcase_36 | AC | 94 ms
71,772 KB |
testcase_37 | AC | 95 ms
71,848 KB |
testcase_38 | WA | - |
testcase_39 | AC | 98 ms
72,424 KB |
ソースコード
from collections import deque import sys sys.setrecursionlimit(10**8) import pypyjit pypyjit.set_param("max_unroll_recursion=-1") class Dinic: def __init__(self, n): """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): """sからtへの残余ネットワーク上での最短距離""" 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 for i in range(self.progress[v], len(self.links[v])): self.progress[v] = i cap, to, rev = self.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 # 残余ネットワークの更新 self.links[v][i][0] -= d self.links[to][rev][0] += d return d return 0 def max_flow(self, s, t): """最大フローを求める""" flow = 0 while True: # tに到達できるか 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()) G = [list() for _ in range(N)] edge = [] for i in range(M): u, v, p, q, w = map(int, input().split()) u-=1;v-=1 G[u].append(p) G[v].append(q+d) edge.append([u, v, p, q, w]) ver = {} for i in range(N): G[i].sort() for i in range(N): for j in range(len(G[i])): ver[(i, G[i][j])] = len(ver) dinic = Dinic(len(ver)) for i in range(N): for j in range(len(G[i])-1): dinic.add_link(ver[(i, G[i][j])], ver[(i, G[i][j+1])], float('inf')) for u, v, p, q, w in edge: dinic.add_link(ver[(u, p)], ver[(v, q+d)], w) if len(G[0])>0 and len(G[-1])>0: print(dinic.max_flow(ver[(0,G[0][0])],ver[(N-1,G[N-1][-1])])) else: print(0)