結果
問題 | No.654 Air E869120 |
ユーザー | marroncastle |
提出日時 | 2020-09-29 21:44:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 231 ms / 2,000 ms |
コード長 | 1,972 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 82,172 KB |
実行使用メモリ | 87,868 KB |
最終ジャッジ日時 | 2024-07-04 13:25:22 |
合計ジャッジ時間 | 5,186 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
54,528 KB |
testcase_01 | AC | 45 ms
54,144 KB |
testcase_02 | AC | 45 ms
54,400 KB |
testcase_03 | AC | 44 ms
54,272 KB |
testcase_04 | AC | 43 ms
54,016 KB |
testcase_05 | AC | 43 ms
54,272 KB |
testcase_06 | AC | 46 ms
54,400 KB |
testcase_07 | AC | 46 ms
54,400 KB |
testcase_08 | AC | 45 ms
54,528 KB |
testcase_09 | AC | 45 ms
54,016 KB |
testcase_10 | AC | 231 ms
87,868 KB |
testcase_11 | AC | 171 ms
84,608 KB |
testcase_12 | AC | 174 ms
84,992 KB |
testcase_13 | AC | 164 ms
84,992 KB |
testcase_14 | AC | 154 ms
84,224 KB |
testcase_15 | AC | 175 ms
86,400 KB |
testcase_16 | AC | 129 ms
80,640 KB |
testcase_17 | AC | 130 ms
80,640 KB |
testcase_18 | AC | 130 ms
80,768 KB |
testcase_19 | AC | 142 ms
80,128 KB |
testcase_20 | AC | 114 ms
78,848 KB |
testcase_21 | AC | 115 ms
78,848 KB |
testcase_22 | AC | 98 ms
78,464 KB |
testcase_23 | AC | 107 ms
78,720 KB |
testcase_24 | AC | 116 ms
78,976 KB |
testcase_25 | AC | 94 ms
77,696 KB |
testcase_26 | AC | 98 ms
78,080 KB |
testcase_27 | AC | 73 ms
70,400 KB |
testcase_28 | AC | 94 ms
77,824 KB |
testcase_29 | AC | 73 ms
70,016 KB |
testcase_30 | AC | 63 ms
64,512 KB |
testcase_31 | AC | 61 ms
64,512 KB |
testcase_32 | AC | 63 ms
65,280 KB |
testcase_33 | AC | 62 ms
64,768 KB |
testcase_34 | AC | 61 ms
64,640 KB |
testcase_35 | AC | 45 ms
53,760 KB |
testcase_36 | AC | 44 ms
53,760 KB |
testcase_37 | AC | 44 ms
53,888 KB |
testcase_38 | AC | 44 ms
53,760 KB |
testcase_39 | AC | 55 ms
61,952 KB |
ソースコード
# Dinic's algorithm O(|V|^2|E|) from collections import deque class Dinic: def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap): forward = [to, cap, 0, None] forward[3] = backward = [fr, 0, 0, forward] self.G[fr].append(forward) self.G[to].append(backward) def add_multi_edge(self, v1, v2, cap1, cap2): edge1 = [v2, cap1, 0, None] edge1[3] = edge2 = [v1, cap2, 0, edge1] self.G[v1].append(edge1) self.G[v2].append(edge2) def bfs(self, s, t): self.level = level = [None]*self.N deq = deque([s]) level[s] = 0 G = self.G while deq: v = deq.popleft() lv = level[v] + 1 for w, cap, _, _ in G[v]: if cap and level[w] is None: level[w] = lv deq.append(w) return level[t] is not None def dfs(self, v, t, f): if v == t: return f level = self.level for e in self.it[v]: w, cap, flow, rev = e if cap and level[v] < level[w]: d = self.dfs(w, t, min(f, cap)) if d: e[1] -= d if rev[2]==0: e[2] += d else: rev[2] -= d rev[1] += d return d return 0 def flow(self, s, t): flow = 0 INF = 10**9 + 7 G = self.G while self.bfs(s, t): *self.it, = map(iter, self.G) f = INF while f: f = self.dfs(s, t, INF) flow += f return flow import sys readline = sys.stdin.readline INF = 10**18 N, M, d = map(int, readline().split()) dinic = Dinic(2*M+2) fr = [0]*M to = [0]*M for i in range(M): u, v, p, q, w = map(int, readline().split()) dinic.add_edge(1+i, 1+M+i, w) fr[i] = (u,p) to[i] = (v,q+d) if u==1: dinic.add_edge(0,1+i,INF) if v==N: dinic.add_edge(1+M+i,2*M+1,INF) for i,(v,q) in enumerate(to): for j,(u,p) in enumerate(fr): if v==u and q<=p: dinic.add_edge(1+M+i,1+j,INF) ans = dinic.flow(0, 2*M+1) print(ans)