結果
問題 | No.654 Air E869120 |
ユーザー | Coki628 |
提出日時 | 2020-01-09 18:33:29 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,572 bytes |
コンパイル時間 | 144 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 169,088 KB |
最終ジャッジ日時 | 2024-11-23 04:02:33 |
合計ジャッジ時間 | 12,284 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
11,392 KB |
testcase_01 | AC | 33 ms
11,008 KB |
testcase_02 | AC | 33 ms
11,136 KB |
testcase_03 | AC | 33 ms
11,136 KB |
testcase_04 | AC | 33 ms
11,264 KB |
testcase_05 | AC | 32 ms
11,264 KB |
testcase_06 | AC | 32 ms
11,136 KB |
testcase_07 | AC | 34 ms
11,136 KB |
testcase_08 | AC | 34 ms
11,136 KB |
testcase_09 | AC | 33 ms
11,264 KB |
testcase_10 | AC | 205 ms
11,776 KB |
testcase_11 | AC | 180 ms
11,904 KB |
testcase_12 | AC | 168 ms
11,904 KB |
testcase_13 | AC | 187 ms
11,776 KB |
testcase_14 | AC | 179 ms
12,032 KB |
testcase_15 | AC | 169 ms
11,904 KB |
testcase_16 | AC | 260 ms
14,868 KB |
testcase_17 | AC | 294 ms
14,740 KB |
testcase_18 | AC | 259 ms
14,864 KB |
testcase_19 | AC | 280 ms
14,740 KB |
testcase_20 | AC | 112 ms
17,280 KB |
testcase_21 | AC | 121 ms
17,152 KB |
testcase_22 | AC | 75 ms
17,280 KB |
testcase_23 | AC | 94 ms
17,280 KB |
testcase_24 | AC | 115 ms
17,152 KB |
testcase_25 | AC | 70 ms
17,152 KB |
testcase_26 | AC | 83 ms
17,152 KB |
testcase_27 | AC | 83 ms
20,096 KB |
testcase_28 | AC | 95 ms
20,096 KB |
testcase_29 | AC | 82 ms
19,968 KB |
testcase_30 | AC | 1,434 ms
169,088 KB |
testcase_31 | AC | 1,427 ms
169,088 KB |
testcase_32 | AC | 1,435 ms
169,088 KB |
testcase_33 | RE | - |
testcase_34 | AC | 1,453 ms
169,088 KB |
testcase_35 | AC | 33 ms
11,392 KB |
testcase_36 | AC | 34 ms
11,136 KB |
testcase_37 | AC | 33 ms
11,392 KB |
testcase_38 | AC | 33 ms
11,136 KB |
testcase_39 | AC | 33 ms
11,392 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) # 例外処理(最初の街を出発する便がない) if not A[0]: print(0) exit() # 出発と到着の頂点を確認してフローを流す 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)