結果

問題 No.654 Air E869120
ユーザー tcltktcltk
提出日時 2021-06-28 02:01:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 2,514 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 93,660 KB
最終ジャッジ日時 2023-09-07 18:10:43
合計ジャッジ時間 12,886 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 209 ms
81,060 KB
testcase_01 AC 204 ms
80,916 KB
testcase_02 AC 201 ms
80,884 KB
testcase_03 AC 209 ms
80,900 KB
testcase_04 AC 206 ms
80,992 KB
testcase_05 AC 199 ms
81,108 KB
testcase_06 AC 205 ms
81,088 KB
testcase_07 AC 204 ms
80,972 KB
testcase_08 AC 212 ms
81,156 KB
testcase_09 AC 210 ms
81,056 KB
testcase_10 AC 332 ms
93,660 KB
testcase_11 AC 333 ms
91,824 KB
testcase_12 AC 324 ms
91,644 KB
testcase_13 AC 339 ms
91,440 KB
testcase_14 AC 324 ms
91,308 KB
testcase_15 AC 320 ms
92,556 KB
testcase_16 AC 296 ms
87,676 KB
testcase_17 AC 292 ms
88,072 KB
testcase_18 AC 286 ms
87,932 KB
testcase_19 AC 297 ms
88,224 KB
testcase_20 AC 288 ms
86,484 KB
testcase_21 AC 289 ms
86,540 KB
testcase_22 AC 272 ms
85,304 KB
testcase_23 AC 276 ms
86,772 KB
testcase_24 AC 279 ms
86,512 KB
testcase_25 AC 254 ms
84,392 KB
testcase_26 AC 272 ms
84,720 KB
testcase_27 AC 265 ms
84,348 KB
testcase_28 AC 263 ms
84,624 KB
testcase_29 AC 259 ms
84,680 KB
testcase_30 AC 251 ms
84,400 KB
testcase_31 AC 245 ms
84,168 KB
testcase_32 AC 246 ms
84,372 KB
testcase_33 AC 250 ms
84,520 KB
testcase_34 AC 248 ms
84,420 KB
testcase_35 AC 206 ms
81,092 KB
testcase_36 AC 203 ms
80,928 KB
testcase_37 AC 209 ms
81,200 KB
testcase_38 AC 208 ms
80,976 KB
testcase_39 AC 220 ms
84,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def 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 = 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):
        depth = [-1] * self.n
        depth[s] = 0
        q = 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] + 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)

INF = 10**15

N, 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:
            continue
        u1, 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)
0