結果
問題 | No.654 Air E869120 |
ユーザー | Mao-beta |
提出日時 | 2020-09-23 23:41:46 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,522 bytes |
コンパイル時間 | 83 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 20,480 KB |
最終ジャッジ日時 | 2024-06-28 04:41:44 |
合計ジャッジ時間 | 5,240 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,136 KB |
testcase_01 | AC | 35 ms
11,136 KB |
testcase_02 | AC | 32 ms
11,264 KB |
testcase_03 | AC | 31 ms
11,264 KB |
testcase_04 | AC | 32 ms
11,264 KB |
testcase_05 | AC | 31 ms
11,136 KB |
testcase_06 | AC | 33 ms
11,136 KB |
testcase_07 | AC | 32 ms
11,264 KB |
testcase_08 | AC | 31 ms
11,264 KB |
testcase_09 | AC | 32 ms
11,264 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 99 ms
12,544 KB |
testcase_27 | AC | 93 ms
12,160 KB |
testcase_28 | WA | - |
testcase_29 | AC | 93 ms
12,032 KB |
testcase_30 | AC | 93 ms
11,392 KB |
testcase_31 | AC | 93 ms
11,392 KB |
testcase_32 | AC | 92 ms
11,392 KB |
testcase_33 | AC | 92 ms
11,392 KB |
testcase_34 | AC | 93 ms
11,392 KB |
testcase_35 | AC | 31 ms
11,392 KB |
testcase_36 | AC | 31 ms
11,136 KB |
testcase_37 | AC | 30 ms
11,136 KB |
testcase_38 | AC | 32 ms
11,264 KB |
testcase_39 | WA | - |
ソースコード
import sys import math from collections import defaultdict from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() class mf_graph: def __init__(self, n=0): self._n = n self.g = [[] for _ in range(n)] self.pos = [] def add_edge(self, frm, to, cap): m = len(self.pos) e1 = mf_graph._edge(to, cap) e2 = mf_graph._edge(frm, 0) e1.rev = e2 e2.rev = e1 self.pos.append(e1) self.g[frm].append(e1) self.g[to].append(e2) return m class edge: def __init__(self, frm, to, cap, flow): self.frm = frm self.to = to self.cap = cap self.flow = flow def __iter__(self): yield self.frm yield self.to yield self.cap yield self.flow def get_edge(self, i): e1 = self.pos[i] e2 = e1.rev return mf_graph.edge(e2.to, e1.to, e1.cap + e2.cap, e2.cap) def edges(self): return [self.get_edge(i) for i in range(len(self.pos))] def change_edge(self, i, new_cap, new_flow): e = self.pos[i] e.cap = new_cap - new_flow e.rev.cap = new_flow def flow(self, s, t, flow_limit=0XFFFFFFFFFFFFFFF): g = self.g flow = 0 while flow < flow_limit: level = [-1] * self._n level[s] = 0 que = [None] * self._n ql = 0 qr = 1 que[0] = s unreached = True while unreached and ql < qr: v = que[ql] ql += 1 for e in g[v]: to = e.to if e.cap and level[to] < 0: level[to] = level[v] + 1 if to == t: unreached = False break que[qr] = to qr += 1 if unreached: return flow ptr = [len(es) for es in g] stack = [] v = t up = flow_limit - flow res = 0 while True: if v == s or not ptr[v]: if v == s: res = up while stack: tmp = res e, up, res = stack.pop() e.cap -= tmp e.rev.cap += tmp res += tmp if res < up: v = e.to break else: flow += res break i = ptr[v] while i: i -= 1 e = g[v][i] if level[e.to] == level[v] - 1 and e.rev.cap: ptr[v] = i stack.append((e.rev, up, res)) v = e.to up = min(up, e.rev.cap) res = 0 break else: ptr[v] = i return flow def min_cut(self, s): visited = [False] * self._n que = [None] * self._n ql = 0 qr = 1 que[0] = s visited[s] = True while ql < qr: p = que[ql] ql += 1 for e in self.g[p]: if e.cap and not visited[e.to]: visited[e.to] = True que[qr] = e.to qr += 1 return visited class _edge: def __init__(self, to, cap): self.to = to self.cap = cap def main(): N, M, d = NMI() planes = [NLI()+[m] for m in range(M)] mf = mf_graph(M+2) for i in range(M): for j in range(i+1, M): P = planes[i] Q = planes[j] if P[1] == Q[0] and P[3]+d <= Q[2]: mf.add_edge(P[5], Q[5], P[4]) if Q[1] == P[0] and Q[3]+d <= P[2]: mf.add_edge(Q[5], P[5], Q[4]) for P in planes: if P[0] == 1: mf.add_edge(M, P[5], 10**15) if P[1] == N: mf.add_edge(P[5], M+1, P[4]) print(mf.flow(M, M+1)) if __name__ == "__main__": main()