結果
問題 | No.654 Air E869120 |
ユーザー | timi |
提出日時 | 2023-08-10 22:20:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 304 ms / 2,000 ms |
コード長 | 2,228 bytes |
コンパイル時間 | 336 ms |
コンパイル使用メモリ | 82,200 KB |
実行使用メモリ | 80,580 KB |
最終ジャッジ日時 | 2024-11-17 08:17:18 |
合計ジャッジ時間 | 6,846 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
56,296 KB |
testcase_01 | AC | 45 ms
55,528 KB |
testcase_02 | AC | 44 ms
55,096 KB |
testcase_03 | AC | 45 ms
55,148 KB |
testcase_04 | AC | 45 ms
54,884 KB |
testcase_05 | AC | 45 ms
54,824 KB |
testcase_06 | AC | 49 ms
61,060 KB |
testcase_07 | AC | 46 ms
55,740 KB |
testcase_08 | AC | 46 ms
55,692 KB |
testcase_09 | AC | 46 ms
55,308 KB |
testcase_10 | AC | 304 ms
79,252 KB |
testcase_11 | AC | 270 ms
78,936 KB |
testcase_12 | AC | 232 ms
78,412 KB |
testcase_13 | AC | 277 ms
79,704 KB |
testcase_14 | AC | 221 ms
78,480 KB |
testcase_15 | AC | 201 ms
77,684 KB |
testcase_16 | AC | 285 ms
80,368 KB |
testcase_17 | AC | 263 ms
79,420 KB |
testcase_18 | AC | 263 ms
79,744 KB |
testcase_19 | AC | 294 ms
80,580 KB |
testcase_20 | AC | 157 ms
78,320 KB |
testcase_21 | AC | 151 ms
78,588 KB |
testcase_22 | AC | 111 ms
77,664 KB |
testcase_23 | AC | 147 ms
78,472 KB |
testcase_24 | AC | 163 ms
78,304 KB |
testcase_25 | AC | 109 ms
77,908 KB |
testcase_26 | AC | 124 ms
78,040 KB |
testcase_27 | AC | 103 ms
77,620 KB |
testcase_28 | AC | 116 ms
77,996 KB |
testcase_29 | AC | 99 ms
77,576 KB |
testcase_30 | AC | 80 ms
74,376 KB |
testcase_31 | AC | 89 ms
77,508 KB |
testcase_32 | AC | 89 ms
77,560 KB |
testcase_33 | AC | 80 ms
74,760 KB |
testcase_34 | AC | 91 ms
77,836 KB |
testcase_35 | AC | 43 ms
54,104 KB |
testcase_36 | AC | 44 ms
54,616 KB |
testcase_37 | AC | 44 ms
54,632 KB |
testcase_38 | AC | 44 ms
55,524 KB |
testcase_39 | AC | 46 ms
54,992 KB |
ソースコード
from collections import deque 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')) D={} N,M,d=map(int, input().split()) D[1]=[0] A=[] for i in range(M): u,v,p,q,w=map(int, input().split()) A.append((u,v,p,q,w)) if u not in D: D[u]=[] D[u].append(p) if v not in D: D[v]=[] D[v].append(q+d) F={} now=0;c=0 for i in range(1,N+1): if i in D: E=D[i] E=sorted(list(set(E))) D[i]=E;c+=len(E) for e in E: F[(i,e)]=now now+=1 mf=Dinic(c) for u,v,p,q,w in A: x,y=F[(u,p)],F[(v,q+d)] mf.add_link(x,y,w) for e in D: G=D[e] for i in range(len(G)-1): x,y=G[i],G[i+1] mf.add_link(F[(e,x)],F[(e,y)],10**12) print(mf.max_flow(0,c-1))