結果

問題 No.654 Air E869120
ユーザー petite_progpetite_prog
提出日時 2020-04-28 09:22:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 4,447 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-05-03 05:30:20
合計ジャッジ時間 4,760 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
11,392 KB
testcase_01 AC 38 ms
11,520 KB
testcase_02 AC 37 ms
11,520 KB
testcase_03 AC 37 ms
11,392 KB
testcase_04 AC 37 ms
11,392 KB
testcase_05 AC 37 ms
11,520 KB
testcase_06 AC 37 ms
11,392 KB
testcase_07 AC 36 ms
11,520 KB
testcase_08 AC 38 ms
11,392 KB
testcase_09 AC 37 ms
11,520 KB
testcase_10 AC 156 ms
11,904 KB
testcase_11 AC 144 ms
11,904 KB
testcase_12 AC 132 ms
11,776 KB
testcase_13 AC 143 ms
11,904 KB
testcase_14 AC 138 ms
11,904 KB
testcase_15 AC 134 ms
11,776 KB
testcase_16 AC 259 ms
12,544 KB
testcase_17 AC 271 ms
12,672 KB
testcase_18 AC 237 ms
12,672 KB
testcase_19 AC 251 ms
12,672 KB
testcase_20 AC 87 ms
12,544 KB
testcase_21 AC 99 ms
12,544 KB
testcase_22 AC 54 ms
12,416 KB
testcase_23 AC 68 ms
12,416 KB
testcase_24 AC 86 ms
12,416 KB
testcase_25 AC 48 ms
12,544 KB
testcase_26 AC 63 ms
12,416 KB
testcase_27 AC 46 ms
12,544 KB
testcase_28 AC 52 ms
12,544 KB
testcase_29 AC 45 ms
12,544 KB
testcase_30 AC 44 ms
12,544 KB
testcase_31 AC 44 ms
12,544 KB
testcase_32 AC 44 ms
12,544 KB
testcase_33 AC 46 ms
12,416 KB
testcase_34 AC 45 ms
12,672 KB
testcase_35 AC 35 ms
11,392 KB
testcase_36 AC 36 ms
11,392 KB
testcase_37 AC 36 ms
11,520 KB
testcase_38 AC 36 ms
11,392 KB
testcase_39 AC 36 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#
#     ⋀_⋀  
#    (・ω・)  
# ./ U ∽ U\
#  │* 合 *│
#  │* 格 *│ 
#  │* 祈 *│ 
#  │* 願 *│ 
#  │*   *│ 
#       ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
class Dinitz:
    #edge := (to, capa, rev_index)

    def __init__(self, N):
        self.__N = N
        self.__Graph = [[] for _ in range(N)] #to, capa, rev_index
        self.__level = [0] * N
        self.__iter = [0]*N

    def add_edge(self, from_, to, capa):
        self.__Graph[from_].append([to, capa, len(self.__Graph[to])])
        self.__Graph[to].append([from_, 0, len(self.__Graph[from_])-1 ])
    
    def solve(self, source:int, target:int):
        self.__target = target
        flow = 0
        while self.leveling_bfs(source):
            self.__iter = [0] * self.__N
            while True:
                delta = self.dfs(source, inf)
                if not delta:
                    break
                flow += delta
        return flow


    def leveling_bfs(self, source: int) -> bool:
        self.__level = [-1] * self.__N
        self.__level[source] = 0
        queue = deque([source])

        pop = queue.popleft
        append = queue.append
        while queue:
            from_ = pop()
            for to, capa, _ in self.__Graph[from_]:
                if capa > 0 > self.__level[to]:
                    self.__level[to] = self.__level[from_] + 1
                    append(to)
        return self.__level[self.__target] != -1 #到達可能ならTrue

    def dfs(self, from_:int,  flow:int) ->int:
        if from_ == self.__target:
            return flow
        for i in range(self.__iter[from_], len(self.__Graph[from_])):
            self.__iter[from_] = i
            to, capa, rev = edge = self.__Graph[from_][i]
            if capa and self.__level[from_] < self.__level[to]:
                delta = self.dfs(to, min(flow,capa))
                if delta: #増加パス
                    edge[1] -= delta #capaをへらす
                    self.__Graph[to][rev][1] += delta #逆辺のcapaを増やす
                    return delta
        return 0
    
def main():
    N,M,D = MI()
    UVPQW = []

    times = [set()for _ in range(N)]
    for _ in range(M):
        u,v,p,q,w = MI()
        u-=1
        v-=1
        UVPQW.append((u,v,p,q,w))
        times[u].add(p)
        times[v].add(q+D)
    
    for i,n in enumerate(times):
        times[i] = sorted(list(n))

    ID = [{} for _ in range(N)]
    cnt = 0
    for i,time in enumerate(times):
        for t in time:
            ID[i][t] = cnt
            cnt += 1

    dinic = Dinitz(cnt)
    add_edge = dinic.add_edge
    solve = dinic.solve

    #飛行機で移動する辺
    for u,v,p,q,w in UVPQW:
        from_ = ID[u][p]
        to = ID[v][q+D]
        add_edge(from_, to, w)
    #空港で待つ辺
    for i,time in enumerate(times):
        for j,t in enumerate(time[:-1]):
            from_ = ID[i][t]
            to_time = time[j+1]
            to = ID[i][to_time]
            add_edge(from_, to, inf)
    
    ans = solve(0,cnt-1)
    print(ans)
    



        
    edges = [[]for _ in range(N)]
    



    """
    for _ in range(M):
        edges[u].append(v)
        nodes

    #
    
    uvpqw=[]
    for _ in range(M):
        u-=1
        v-=1
        uvpqw.append()

    ans = solve(0,N-1)"""

if __name__ == '__main__':
    main()
0