結果

問題 No.654 Air E869120
ユーザー kamojirokamojiro
提出日時 2020-06-11 22:08:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,234 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 11,140 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2023-09-06 08:39:26
合計ジャッジ時間 3,458 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,832 KB
testcase_01 AC 20 ms
8,916 KB
testcase_02 AC 20 ms
8,796 KB
testcase_03 AC 19 ms
8,880 KB
testcase_04 AC 20 ms
8,700 KB
testcase_05 AC 19 ms
8,872 KB
testcase_06 AC 20 ms
8,740 KB
testcase_07 AC 19 ms
8,780 KB
testcase_08 AC 20 ms
8,752 KB
testcase_09 AC 19 ms
8,780 KB
testcase_10 AC 104 ms
9,260 KB
testcase_11 AC 80 ms
9,404 KB
testcase_12 AC 85 ms
9,308 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 118 ms
10,100 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 43 ms
10,144 KB
testcase_21 AC 40 ms
10,124 KB
testcase_22 AC 30 ms
9,940 KB
testcase_23 AC 38 ms
10,004 KB
testcase_24 WA -
testcase_25 AC 28 ms
9,936 KB
testcase_26 AC 33 ms
10,008 KB
testcase_27 AC 28 ms
9,948 KB
testcase_28 WA -
testcase_29 AC 27 ms
9,904 KB
testcase_30 AC 26 ms
10,000 KB
testcase_31 AC 26 ms
10,020 KB
testcase_32 AC 26 ms
9,976 KB
testcase_33 AC 26 ms
9,952 KB
testcase_34 AC 26 ms
9,920 KB
testcase_35 AC 20 ms
8,732 KB
testcase_36 AC 20 ms
8,732 KB
testcase_37 AC 19 ms
8,892 KB
testcase_38 AC 20 ms
8,876 KB
testcase_39 AC 20 ms
8,920 KB
権限があれば一括ダウンロードができます

ソースコード

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)]
    E = [set() for _ in range(N)]
    L = 10**9
    E[0].add(0)
    E[N-1].add(L)
    for u, v, p, q, _ in UVPQW:
        u, v = u-1, v-1
        E[u].add(p)
        E[v].add(q+d)
    F = [sorted(list(E[i])) for i in range(N)]
    index = 0
    VtoI = defaultdict( int)
    for i in range(N):
        for v in F[i]:
            VtoI[(i,v)] = index
            index += 1
    I = index
    G = [[] for _ in range(I)]
    capacity = defaultdict( int)
    for u,v,p,q,w in UVPQW:
        u, v = u-1, v-1
        q += d
        # if q > L:
        #     continue
        a = VtoI[(u,p)]
        b = VtoI[(v,q)]
        G[a].append(b)
        capacity[(a,b)] = +w
        G[b].append(a)
    for i in range(N):
        lg = len(F[i])
        for j in range(lg-1):
            a = VtoI[(i,F[i][j])]
            b = VtoI[(i, F[i][j+1])]
            G[a].append(b)
            capacity[(a,b)] = INF
            G[b].append(a)
    s = VtoI[(0,0)]
    g = VtoI[(N-1,L)]
    # print(G)
    print( Ford_Fulkerson(I,G,capacity,s,g))
    
if __name__ == '__main__':
    main()
0