結果
問題 | No.654 Air E869120 |
ユーザー | zundamo-ti |
提出日時 | 2021-01-20 00:24:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 661 ms / 2,000 ms |
コード長 | 2,473 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,452 KB |
実行使用メモリ | 86,044 KB |
最終ジャッジ日時 | 2024-05-10 01:42:04 |
合計ジャッジ時間 | 7,492 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,528 KB |
testcase_01 | AC | 44 ms
54,912 KB |
testcase_02 | AC | 43 ms
54,528 KB |
testcase_03 | AC | 43 ms
54,656 KB |
testcase_04 | AC | 43 ms
54,400 KB |
testcase_05 | AC | 44 ms
54,520 KB |
testcase_06 | AC | 44 ms
55,168 KB |
testcase_07 | AC | 43 ms
54,656 KB |
testcase_08 | AC | 44 ms
54,656 KB |
testcase_09 | AC | 44 ms
54,272 KB |
testcase_10 | AC | 661 ms
86,044 KB |
testcase_11 | AC | 429 ms
83,692 KB |
testcase_12 | AC | 587 ms
84,268 KB |
testcase_13 | AC | 521 ms
83,772 KB |
testcase_14 | AC | 400 ms
82,916 KB |
testcase_15 | AC | 480 ms
85,468 KB |
testcase_16 | AC | 179 ms
80,628 KB |
testcase_17 | AC | 176 ms
80,384 KB |
testcase_18 | AC | 158 ms
80,128 KB |
testcase_19 | AC | 165 ms
80,452 KB |
testcase_20 | AC | 138 ms
79,224 KB |
testcase_21 | AC | 141 ms
79,248 KB |
testcase_22 | AC | 110 ms
78,720 KB |
testcase_23 | AC | 132 ms
79,104 KB |
testcase_24 | AC | 139 ms
79,332 KB |
testcase_25 | AC | 101 ms
77,824 KB |
testcase_26 | AC | 119 ms
79,036 KB |
testcase_27 | AC | 97 ms
77,952 KB |
testcase_28 | AC | 109 ms
78,208 KB |
testcase_29 | AC | 78 ms
73,344 KB |
testcase_30 | AC | 64 ms
66,816 KB |
testcase_31 | AC | 64 ms
67,048 KB |
testcase_32 | AC | 68 ms
67,712 KB |
testcase_33 | AC | 65 ms
67,344 KB |
testcase_34 | AC | 63 ms
66,816 KB |
testcase_35 | AC | 44 ms
53,632 KB |
testcase_36 | AC | 44 ms
54,016 KB |
testcase_37 | AC | 44 ms
53,888 KB |
testcase_38 | AC | 43 ms
54,272 KB |
testcase_39 | AC | 52 ms
62,976 KB |
ソースコード
import sys from collections import deque readline = sys.stdin.readline class Edge(): def __init__(self, to, cap, rev): self.to = to self.cap = cap self.rev = rev class Dinic(): def __init__(self, N, inf = float('inf')): self.N = N self.G = [[] for _ in range(N)] self.level = [-1]*N self.it = [0]*N self.inf = inf def add_edge(self, fr, to, cap): self.G[fr].append(Edge(to, cap, len(self.G[to]))) self.G[to].append(Edge(fr, 0, len(self.G[fr]) - 1)) def bfs(self, s): self.level = [-1]*self.N q = deque([s]) self.level[s] = 0 while q: v = q.popleft() for i in range(len(self.G[v])): e = self.G[v][i] if e.cap > 0 and self.level[e.to] < 0: self.level[e.to] = self.level[v] + 1 q.append(e.to) def dfs(self, v, t, f): if v == t: return f for i in range(self.it[v], len(self.G[v])): e = self.G[v][i] if e.cap > 0 and self.level[v] < self.level[e.to]: d = self.dfs(e.to, t, min(f, e.cap)) if d > 0: e.cap -= d self.G[e.to][e.rev].cap += d return d return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.level[t] < 0: return flow self.it = [0]*self.N f = self.dfs(s, t, self.inf) while f > 0: flow += f f = self.dfs(s, t, self.inf) def main(): INF = float('inf') N, M, d = map(int, readline().split()) dinic = Dinic(2*M + 2) vertex = [None]*(2*M + 2) for i in range(1, M + 1): u, v, p, q, w = map(int, readline().split()) vertex[i] = (u, p) vertex[i + M] = (v, q) dinic.add_edge(i, i + M, w) for i in range(M + 1, 2*M + 1): v, q = vertex[i] for j in range(1, M + 1): u, p = vertex[j] if v == u and q + d <= p: dinic.add_edge(i, j, INF) for i in range(1, M + 1): u, p = vertex[i] if u == 1: dinic.add_edge(0, i, INF) v, q = vertex[i + M] if v == N: dinic.add_edge(i + M, 2*M + 1, INF) f = dinic.max_flow(0, 2*M + 1) print(f) if __name__ == '__main__': main()