結果
問題 | No.654 Air E869120 |
ユーザー | kamojiro |
提出日時 | 2020-06-11 00:31:38 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,506 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 19,356 KB |
最終ジャッジ日時 | 2024-06-23 20:45:17 |
合計ジャッジ時間 | 12,311 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
18,076 KB |
testcase_01 | AC | 31 ms
11,008 KB |
testcase_02 | AC | 31 ms
11,136 KB |
testcase_03 | AC | 34 ms
11,008 KB |
testcase_04 | AC | 32 ms
11,008 KB |
testcase_05 | AC | 31 ms
10,880 KB |
testcase_06 | AC | 32 ms
11,008 KB |
testcase_07 | AC | 32 ms
11,008 KB |
testcase_08 | AC | 31 ms
10,880 KB |
testcase_09 | AC | 31 ms
11,008 KB |
testcase_10 | AC | 1,825 ms
11,776 KB |
testcase_11 | AC | 1,251 ms
11,648 KB |
testcase_12 | AC | 1,140 ms
11,520 KB |
testcase_13 | AC | 1,877 ms
11,776 KB |
testcase_14 | AC | 896 ms
11,648 KB |
testcase_15 | AC | 1,067 ms
11,648 KB |
testcase_16 | TLE | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import defaultdict INF = 10**18 def dfs_for_Ford_Fulkerson(N,E,capacity,s,g,flowing): stack = [(s,INF)] root = [0]*N root[s] = -1 V = [False]*N V[s] = True while stack: u, flow = stack.pop() for v in E[u]: if not V[v] and capacity[(u,v)] > 0: root[v] = u V[v] = True if v == g: if capacity[(u,v)] < flow: flow = capacity[(u,v)] break stack.append((v, min(flow, capacity[(u,v)]))) else: continue break else: return False now = g while now != s: before = root[now] capacity[(before, now)] -= flow capacity[(now, before)] += flow now = before flowing[0] += flow return True def Ford_Fulkerson(N,E,capacity, s, g): flowing = [0] while dfs_for_Ford_Fulkerson(N,E,capacity,s,g, flowing): pass return flowing[0] def main(): N, M, D = map(int, readline().split()) m = map(int, read().split()) U, V, P, Q, W = zip(*zip(m, m, m, m, m)) # U, V, P, Q, W = [], [], [], [], [] # for _ in range(M): # u,v,p,q,w = map( int, input().split()) # U.append(u) # V.append(v) # P.append(p) # Q.append(q) # W.append(w) X = [(u << 32) + p for u, p in zip(U, P)] Y = [(v << 32) + q + D for v, q in zip(V, Q)] nodes = sorted(set(X + Y)) ind = {x: i for i, x in enumerate(nodes)} L = len(nodes) source = L sink = L + 1 G = [[] for _ in range(L+2)] capacity = defaultdict( int) u, t = divmod(nodes[0], 1 << 32) if u == 1: G[source].append(0) capacity[(source, 0)] = INF G[0].append(source) u, t = divmod(nodes[-1], 1 << 32) if u == N: G[L-1].append(sink) capacity[(L-1, sink)] = INF G[sink].append(L-1) for i, (x, y) in enumerate(zip(nodes, nodes[1:])): if x >> 32 == y >> 32: G[i].append(i+1) capacity[(i, i+1)] = INF G[i+1].append(i) for x, y, w in zip(X, Y, W): G[ind[x]].append(ind[y]) capacity[(ind[x], ind[y])] += w G[ind[y]].append(ind[x]) print( Ford_Fulkerson(L+2,G,capacity,source,sink)) if __name__ == '__main__': main()