結果
問題 | No.654 Air E869120 |
ユーザー |
|
提出日時 | 2021-06-28 02:01:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 278 ms / 2,000 ms |
コード長 | 2,514 bytes |
コンパイル時間 | 322 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 97,664 KB |
最終ジャッジ日時 | 2024-06-25 11:57:30 |
合計ジャッジ時間 | 9,849 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
#!/usr/bin/env python3# from typing import *import sysimport ioimport mathimport collectionsimport decimalimport itertoolsimport bisectimport heapqdef input():return sys.stdin.readline()[:-1]# sys.setrecursionlimit(1000000)# _INPUT = """# paste here...# """# sys.stdin = io.StringIO(_INPUT)class Dinic:def __init__(self, n):self.n = nself.links = [[] for _ in range(n)]self.depth = Noneself.progress = Nonedef 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):depth = [-1] * self.ndepth[s] = 0q = collections.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] + 1q.append(to)self.depth = depthdef dfs(self, v, t, flow):if v == t:return flowlinks_v = self.links[v]for i in range(self.progress[v], len(links_v)):self.progress[v] = icap, to, rev = link = links_v[i]if cap == 0 or self.depth[v] >= self.depth[to]:continued = self.dfs(to, t, min(flow, cap))if d == 0:continuelink[0] -= dself.links[to][rev][0] += dreturn dreturn 0def max_flow(self, s, t):flow = 0while True:self.bfs(s)if self.depth[t] < 0:return flowself.progress = [0] * self.ncurrent_flow = self.dfs(s, t, INF)while current_flow > 0:flow += current_flowcurrent_flow = self.dfs(s, t, INF)INF = 10**15N, M, D = map(int, input().split())mf = Dinic(2*M+2)Freight = []for i in range(M):u, v, p, q, w = map(int, input().split())Freight.append((u-1, v-1, p, q, w))mf.add_link(2*i+1, 2*i+2, w)if u == 1:mf.add_link(0, 2*i+1, INF)if v == N:mf.add_link(2*i+2, 2*M+1, INF)for i1 in range(M):for i2 in range(M):if i1 == i2:continueu1, v1, p1, q1, w1 = Freight[i1]u2, v2, p2, q2, w2 = Freight[i2]if v1 == u2 and q1+D <= p2:mf.add_link(2*i1+2, 2*i2+1, INF)flow = mf.max_flow(0, 2*M+1)print(flow)