結果
問題 | No.654 Air E869120 |
ユーザー | Coki628 |
提出日時 | 2020-01-09 18:37:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 360 ms / 2,000 ms |
コード長 | 3,619 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 149,376 KB |
最終ジャッジ日時 | 2024-11-23 04:03:47 |
合計ジャッジ時間 | 7,864 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
55,168 KB |
testcase_01 | AC | 47 ms
55,040 KB |
testcase_02 | AC | 48 ms
55,040 KB |
testcase_03 | AC | 49 ms
54,528 KB |
testcase_04 | AC | 47 ms
54,912 KB |
testcase_05 | AC | 48 ms
54,656 KB |
testcase_06 | AC | 60 ms
61,184 KB |
testcase_07 | AC | 51 ms
55,296 KB |
testcase_08 | AC | 51 ms
55,296 KB |
testcase_09 | AC | 47 ms
54,912 KB |
testcase_10 | AC | 300 ms
80,256 KB |
testcase_11 | AC | 268 ms
79,872 KB |
testcase_12 | AC | 306 ms
80,308 KB |
testcase_13 | AC | 273 ms
79,232 KB |
testcase_14 | AC | 273 ms
80,000 KB |
testcase_15 | AC | 265 ms
79,744 KB |
testcase_16 | AC | 269 ms
87,168 KB |
testcase_17 | AC | 360 ms
90,880 KB |
testcase_18 | AC | 315 ms
88,064 KB |
testcase_19 | AC | 290 ms
88,576 KB |
testcase_20 | AC | 184 ms
92,800 KB |
testcase_21 | AC | 188 ms
91,264 KB |
testcase_22 | AC | 119 ms
85,760 KB |
testcase_23 | AC | 150 ms
87,296 KB |
testcase_24 | AC | 193 ms
92,416 KB |
testcase_25 | AC | 110 ms
84,096 KB |
testcase_26 | AC | 152 ms
87,808 KB |
testcase_27 | AC | 99 ms
83,712 KB |
testcase_28 | AC | 138 ms
93,824 KB |
testcase_29 | AC | 102 ms
84,096 KB |
testcase_30 | AC | 172 ms
149,120 KB |
testcase_31 | AC | 168 ms
148,992 KB |
testcase_32 | AC | 166 ms
149,376 KB |
testcase_33 | AC | 158 ms
133,120 KB |
testcase_34 | AC | 167 ms
148,864 KB |
testcase_35 | AC | 45 ms
54,528 KB |
testcase_36 | AC | 45 ms
54,400 KB |
testcase_37 | AC | 45 ms
54,784 KB |
testcase_38 | AC | 45 ms
54,400 KB |
testcase_39 | AC | 47 ms
55,040 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] or not A[N-1]: 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)