結果

問題 No.904 サメトロ
ユーザー hahho28hahho28
提出日時 2021-04-05 09:00:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 742 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 43,372 KB
最終ジャッジ日時 2023-08-28 20:13:27
合計ジャッジ時間 5,536 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 188 ms
43,084 KB
testcase_01 WA -
testcase_02 AC 184 ms
43,136 KB
testcase_03 WA -
testcase_04 AC 188 ms
43,068 KB
testcase_05 AC 187 ms
43,092 KB
testcase_06 AC 188 ms
43,076 KB
testcase_07 WA -
testcase_08 AC 187 ms
43,148 KB
testcase_09 AC 185 ms
43,156 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 186 ms
43,128 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 188 ms
43,284 KB
testcase_16 WA -
testcase_17 AC 188 ms
43,060 KB
testcase_18 AC 187 ms
43,076 KB
testcase_19 WA -
testcase_20 AC 186 ms
43,064 KB
testcase_21 WA -
testcase_22 AC 186 ms
43,116 KB
testcase_23 WA -
testcase_24 AC 186 ms
43,324 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 186 ms
43,244 KB
testcase_28 AC 184 ms
43,076 KB
testcase_29 AC 185 ms
43,196 KB
testcase_30 WA -
testcase_31 AC 186 ms
43,136 KB
testcase_32 AC 186 ms
43,132 KB
testcase_33 AC 186 ms
43,076 KB
testcase_34 AC 186 ms
43,160 KB
testcase_35 AC 189 ms
43,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
from scipy.sparse.csgraph import maximum_flow
from scipy.sparse import csr_matrix
from itertools import product

def solve(ab):
    INF = 10**9
    ab = [(INF,INF)]+ab
    n = len(ab)

    g = np.zeros((2*n+2,2*n+2), dtype=int)

    # 0: start, 1: goal, 2-(n+1): left, (n+2)-(2n-1): right

    for i,(a,b) in enumerate(ab):
        g[0,i+2] = a
        g[i+n+2,1] = b
    for i,j in product(range(n), repeat=2):
        if i == j:
            continue
        g[i+2,j+n+2] = INF

    t = maximum_flow(csr_matrix(g), 0, 1).flow_value

    ta = sum(a for a,b in ab[1:])
    tb = sum(b for a,b in ab[1:])

    return t-max(ta,tb)+1


n = int(input())
ab = [tuple(map(int,input().split())) for _ in range(n-1)]
print(solve(ab))
0