結果
問題 | No.654 Air E869120 |
ユーザー | ああいい |
提出日時 | 2022-04-14 11:46:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 262 ms / 2,000 ms |
コード長 | 3,263 bytes |
コンパイル時間 | 521 ms |
コンパイル使用メモリ | 82,020 KB |
実行使用メモリ | 88,832 KB |
最終ジャッジ日時 | 2024-06-06 14:11:38 |
合計ジャッジ時間 | 5,580 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
59,648 KB |
testcase_01 | AC | 41 ms
59,776 KB |
testcase_02 | AC | 41 ms
59,904 KB |
testcase_03 | AC | 40 ms
59,392 KB |
testcase_04 | AC | 46 ms
59,392 KB |
testcase_05 | AC | 39 ms
59,648 KB |
testcase_06 | AC | 40 ms
59,520 KB |
testcase_07 | AC | 42 ms
60,032 KB |
testcase_08 | AC | 40 ms
59,264 KB |
testcase_09 | AC | 40 ms
59,136 KB |
testcase_10 | AC | 262 ms
88,832 KB |
testcase_11 | AC | 209 ms
86,156 KB |
testcase_12 | AC | 206 ms
86,144 KB |
testcase_13 | AC | 205 ms
86,372 KB |
testcase_14 | AC | 197 ms
84,788 KB |
testcase_15 | AC | 210 ms
88,064 KB |
testcase_16 | AC | 139 ms
81,496 KB |
testcase_17 | AC | 143 ms
81,076 KB |
testcase_18 | AC | 134 ms
81,280 KB |
testcase_19 | AC | 149 ms
81,440 KB |
testcase_20 | AC | 130 ms
79,748 KB |
testcase_21 | AC | 128 ms
80,128 KB |
testcase_22 | AC | 104 ms
78,208 KB |
testcase_23 | AC | 116 ms
79,872 KB |
testcase_24 | AC | 121 ms
80,040 KB |
testcase_25 | AC | 97 ms
77,696 KB |
testcase_26 | AC | 106 ms
78,368 KB |
testcase_27 | AC | 94 ms
77,576 KB |
testcase_28 | AC | 102 ms
77,568 KB |
testcase_29 | AC | 86 ms
77,664 KB |
testcase_30 | AC | 59 ms
69,248 KB |
testcase_31 | AC | 62 ms
69,248 KB |
testcase_32 | AC | 59 ms
69,420 KB |
testcase_33 | AC | 62 ms
69,120 KB |
testcase_34 | AC | 64 ms
69,248 KB |
testcase_35 | AC | 42 ms
54,144 KB |
testcase_36 | AC | 39 ms
54,912 KB |
testcase_37 | AC | 42 ms
54,400 KB |
testcase_38 | AC | 40 ms
54,368 KB |
testcase_39 | AC | 42 ms
60,544 KB |
ソースコード
#Dinic法で最大流を求める #deque のimport が必要 #逆辺追加しなきゃいけないから、 #グラフの構成はadd_edgeで行う #最大流は flow メソッドで from collections import deque class Dinic: def __init__(self,N): self.N = N self.G = [[] for _ in range(N)] self.level = None self.progress = None self.edge = [] def add_edge(self,fr,to,cap): forward = [to,cap,None] forward[2] = backward = [fr,0,forward] self.G[fr].append(forward) self.G[to].append(backward) self.edge.append(forward) def add_multi_edge(self,v1,v2,cap1,cap2): edge1 = [v2,cap1,None] edge1[2] = edge2 = [v1,cap2,edge1] self.G[v1].append(edge1) self.G[v2].append(edge2) self.edge.append(edge1) def get_edge(self,i): return self.edge[i] # i 回目に追加した辺のポインタを返す # 0-index, 順辺のみ def bfs(self,s,t): self.level = level = [None] * self.N q = deque([s]) level[s] = 0 G = self.G while q: v = q.popleft() lv = level[v] + 1 for w,cap,_ in G[v]: if cap and level[w] is None: level[w] = lv q.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, rev = e if cap and level[v] < level[w]: d = self.dfs(w, t, min(f, cap)) if d: e[1] -= d rev[1] += d return d else: pass else: pass return 0 def flow(self, s, t): flow = 0 INF = 10 ** 18 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 def min_cut(self,s): #最小カットを実現する頂点の分割を与える #True なら source側 #False なら sink側 visited = [False for i in range(self.N)] q = deque([s]) while q: now = q.popleft() visited[now] = True for to,cap,_ in self.G[now]: if cap and not visited[to]: visited[to] = True q.append(to) return visited N,M,dd = map(int,input().split()) G = [[] for _ in range(N)] d = dict() count = 0 for _ in range(M): u,v,p,q,w = map(int,input().split()) u -= 1 v -= 1 G[u].append((v,p,q,w)) d[(v,p,q,w)] = count count += 1 dinic = Dinic(M + 2 + M) s = M + M t = M + M + 1 inf = 10 ** 18 for v,p,q,w in d: count = d[(v,p,q,w)] for vv,pp,qq,ww in G[v]: count2 = d[(vv,pp,qq,ww)] if q + dd <= pp: dinic.add_edge(count + M,count2,inf) if v == N - 1: dinic.add_edge(count + M,t,inf) dinic.add_edge(count,count + M,w) for v,p,q,w in G[0]: dinic.add_edge(s,d[(v,p,q,w)],inf) print(dinic.flow(s,t))