結果

問題 No.654 Air E869120
ユーザー kamojirokamojiro
提出日時 2020-06-11 22:04:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,193 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 82,288 KB
最終ジャッジ日時 2023-09-06 08:39:16
合計ジャッジ時間 9,875 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,676 KB
testcase_01 AC 88 ms
71,560 KB
testcase_02 AC 90 ms
71,396 KB
testcase_03 AC 93 ms
71,532 KB
testcase_04 AC 90 ms
71,816 KB
testcase_05 AC 89 ms
71,552 KB
testcase_06 AC 87 ms
71,556 KB
testcase_07 AC 87 ms
71,608 KB
testcase_08 AC 88 ms
71,812 KB
testcase_09 AC 88 ms
71,552 KB
testcase_10 AC 690 ms
79,604 KB
testcase_11 AC 496 ms
78,872 KB
testcase_12 AC 485 ms
78,776 KB
testcase_13 AC 671 ms
79,040 KB
testcase_14 AC 443 ms
78,996 KB
testcase_15 AC 453 ms
78,712 KB
testcase_16 AC 1,511 ms
82,288 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import defaultdict
INF = 10**13

def dfs_for_Ford_Fulkerson(N,E,capacity,s,g,flowing):
    stack = [(s,INF)]
    root = [0]*N
    root[s] = -1
    V = [False]*N
    V[s] = True
    while stack:
        u, flow = stack.pop()
        for v in E[u]:
            if not V[v] and capacity[(u,v)] > 0:
                root[v] = u
                V[v] = True
                if v == g:
                    if capacity[(u,v)] < flow:
                        flow = capacity[(u,v)]
                    break
                stack.append((v, min(flow, capacity[(u,v)])))
        else:
            continue
        break
    else:
        return False
    now = g
    while now != s:
        before = root[now]
        capacity[(before, now)] -= flow
        capacity[(now, before)] += flow
        now = before
    flowing[0] += flow
    return True

def Ford_Fulkerson(N,E,capacity, s, g):
    flowing = [0]
    while dfs_for_Ford_Fulkerson(N,E,capacity,s,g, flowing):
        pass
    return flowing[0]

def main():
    N, M, d = map( int, input().split())
    UVPQW = [ tuple( map( int, input().split())) for _ in range(M)]
    L = 10**9
    X = [(u << 32)+p for u,_,p,_,_ in UVPQW]
    Y = [(v << 32)+q+d for _,v,_,q,_ in UVPQW]
    nodes = sorted(set(X+Y))
    VtoI = {x: i for i, x in enumerate(nodes)}
    L = len(nodes)
    s = L
    g = L+1
    G = [[] for _ in range(L+2)]
    capacity = defaultdict( int)
    u, t = divmod(nodes[0], 1<<32)
    if u == 1:
        G[s].append(0)
        capacity[(s,0)] = INF
        G[0].append(s)
    u, t = divmod(nodes[-1], 1<<32)
    if u == N:
        G[L-1].append(g)
        capacity[(L-1,g)] = INF
        G[g].append(L-1)

    for i, (x, y) in enumerate(zip(nodes, nodes[1:])):
        if x >> 32 == y >> 32:
            G[i].append(i+1)
            capacity[(i,i+1)] = INF
            G[i+1].append(i)

    W = [ w for _,_,_,_,w in UVPQW]
    for x, y, w in zip(X, Y, W):
        a = VtoI[x]
        b = VtoI[y]
        G[a].append(b)
        capacity[(a,b)] += w
        G[b].append(a)
    # print(L+2)
    print( Ford_Fulkerson(L+2,G,capacity,s,g))
    
if __name__ == '__main__':
    main()
0