結果
問題 | No.654 Air E869120 |
ユーザー | Coki628 |
提出日時 | 2020-01-09 18:29:34 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,478 bytes |
コンパイル時間 | 331 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 169,324 KB |
最終ジャッジ日時 | 2024-11-23 04:02:10 |
合計ジャッジ時間 | 12,959 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
11,264 KB |
testcase_01 | AC | 33 ms
11,136 KB |
testcase_02 | AC | 33 ms
11,264 KB |
testcase_03 | AC | 33 ms
11,136 KB |
testcase_04 | AC | 33 ms
11,264 KB |
testcase_05 | AC | 33 ms
11,136 KB |
testcase_06 | AC | 34 ms
11,264 KB |
testcase_07 | AC | 35 ms
11,136 KB |
testcase_08 | AC | 33 ms
11,136 KB |
testcase_09 | AC | 32 ms
11,136 KB |
testcase_10 | AC | 200 ms
11,776 KB |
testcase_11 | AC | 180 ms
12,032 KB |
testcase_12 | AC | 174 ms
11,904 KB |
testcase_13 | AC | 191 ms
11,904 KB |
testcase_14 | AC | 177 ms
12,032 KB |
testcase_15 | AC | 170 ms
11,776 KB |
testcase_16 | AC | 266 ms
14,868 KB |
testcase_17 | AC | 301 ms
14,860 KB |
testcase_18 | AC | 264 ms
14,860 KB |
testcase_19 | AC | 280 ms
14,732 KB |
testcase_20 | AC | 113 ms
17,152 KB |
testcase_21 | AC | 124 ms
17,152 KB |
testcase_22 | AC | 75 ms
17,280 KB |
testcase_23 | AC | 93 ms
17,152 KB |
testcase_24 | AC | 115 ms
17,280 KB |
testcase_25 | AC | 70 ms
17,152 KB |
testcase_26 | AC | 83 ms
17,152 KB |
testcase_27 | AC | 84 ms
20,096 KB |
testcase_28 | AC | 95 ms
20,096 KB |
testcase_29 | AC | 86 ms
20,096 KB |
testcase_30 | AC | 1,462 ms
168,960 KB |
testcase_31 | AC | 1,439 ms
169,088 KB |
testcase_32 | AC | 1,445 ms
168,960 KB |
testcase_33 | RE | - |
testcase_34 | AC | 1,474 ms
169,324 KB |
testcase_35 | AC | 33 ms
11,136 KB |
testcase_36 | AC | 33 ms
11,136 KB |
testcase_37 | AC | 32 ms
11,008 KB |
testcase_38 | AC | 31 ms
11,136 KB |
testcase_39 | AC | 33 ms
11,136 KB |
ソースコード
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 class Dinic: """ 最大流(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): from collections import deque 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, INF) while current_flow > 0: flow += current_flow current_flow = self.dfs(s, t, INF) def compress(S): """ 座標圧縮 """ zipped, unzipped = {}, {} for i, a in enumerate(sorted(S)): zipped[a] = i unzipped[i] = a return zipped, unzipped N, M, D = MAP() S = set() edges = [] for i in range(M): u, v, p, q, w = MAP() q += D u -= 1; v -= 1 S.add(p) S.add(q) edges.append((u, v, p, q, w)) # 時刻を座標圧縮 zipped, _ = compress(S) for i, (u, v, p, q, w) in enumerate(edges): p = zipped[p] q = zipped[q] edges[i] = (u, v, p, q, w) # フライトの辺を張る L = len(zipped) dn = Dinic(N * L) A = [[] for i in range(N)] for u, v, p, q, w in edges: dn.add_link(u*L+p, v*L+q, w) # 街毎に発着がある時刻を保持 A[u].append(p) A[v].append(q) # 各街で待機する辺を張る for u in range(N): A[u].sort() for i in range(len(A[u])-1): p, q = A[u][i], A[u][i+1] # 発着があって隣り合う時刻同士にだけ辺を張る dn.add_link(u*L+p, u*L+q, INF) # 出発と到着の頂点を確認してフローを流す su = 0 sp = A[0][0] gv = N - 1 gq = A[N-1][-1] ans = dn.max_flow(su*L+sp, gv*L+gq) print(ans)