結果

問題 No.1316 Maximum Minimum Spanning Tree
ユーザー 👑 hitonanodehitonanode
提出日時 2020-12-12 05:06:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 823 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 11,876 KB
実行使用メモリ 53,424 KB
最終ジャッジ日時 2023-10-20 02:25:25
合計ジャッジ時間 73,411 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 738 ms
53,236 KB
testcase_01 AC 731 ms
53,080 KB
testcase_02 AC 719 ms
53,088 KB
testcase_03 AC 737 ms
53,136 KB
testcase_04 AC 740 ms
53,076 KB
testcase_05 AC 737 ms
53,076 KB
testcase_06 AC 744 ms
53,084 KB
testcase_07 AC 914 ms
53,268 KB
testcase_08 AC 912 ms
53,268 KB
testcase_09 AC 901 ms
53,264 KB
testcase_10 AC 905 ms
53,268 KB
testcase_11 AC 795 ms
53,240 KB
testcase_12 AC 801 ms
53,240 KB
testcase_13 AC 805 ms
53,228 KB
testcase_14 AC 806 ms
53,232 KB
testcase_15 WA -
testcase_16 AC 922 ms
53,240 KB
testcase_17 AC 922 ms
53,272 KB
testcase_18 AC 913 ms
53,272 KB
testcase_19 AC 769 ms
53,216 KB
testcase_20 AC 782 ms
53,204 KB
testcase_21 AC 779 ms
53,196 KB
testcase_22 AC 745 ms
53,196 KB
testcase_23 AC 770 ms
53,208 KB
testcase_24 AC 772 ms
53,208 KB
testcase_25 AC 774 ms
53,200 KB
testcase_26 AC 765 ms
53,200 KB
testcase_27 AC 760 ms
53,216 KB
testcase_28 AC 736 ms
53,216 KB
testcase_29 AC 749 ms
53,196 KB
testcase_30 AC 766 ms
53,196 KB
testcase_31 AC 799 ms
53,208 KB
testcase_32 AC 776 ms
53,208 KB
testcase_33 AC 759 ms
53,200 KB
testcase_34 AC 777 ms
53,200 KB
testcase_35 AC 746 ms
53,216 KB
testcase_36 AC 762 ms
53,204 KB
testcase_37 AC 780 ms
53,196 KB
testcase_38 AC 773 ms
53,200 KB
testcase_39 AC 776 ms
53,220 KB
testcase_40 AC 765 ms
53,220 KB
testcase_41 AC 777 ms
53,200 KB
testcase_42 AC 762 ms
53,200 KB
testcase_43 WA -
testcase_44 AC 859 ms
53,248 KB
testcase_45 AC 867 ms
53,248 KB
testcase_46 AC 871 ms
53,244 KB
testcase_47 AC 903 ms
53,264 KB
testcase_48 AC 892 ms
53,256 KB
testcase_49 AC 912 ms
53,248 KB
testcase_50 AC 901 ms
53,256 KB
testcase_51 WA -
testcase_52 AC 910 ms
53,260 KB
testcase_53 AC 905 ms
53,240 KB
testcase_54 AC 905 ms
53,248 KB
testcase_55 AC 917 ms
53,244 KB
testcase_56 AC 914 ms
53,248 KB
testcase_57 AC 906 ms
53,248 KB
testcase_58 AC 908 ms
53,248 KB
testcase_59 AC 899 ms
53,248 KB
testcase_60 AC 910 ms
53,264 KB
testcase_61 AC 886 ms
53,268 KB
testcase_62 AC 893 ms
53,268 KB
testcase_63 AC 893 ms
53,268 KB
testcase_64 AC 885 ms
53,264 KB
testcase_65 AC 904 ms
53,256 KB
testcase_66 AC 908 ms
53,248 KB
testcase_67 AC 913 ms
53,256 KB
testcase_68 AC 918 ms
53,256 KB
testcase_69 AC 930 ms
53,260 KB
testcase_70 AC 938 ms
53,260 KB
testcase_71 AC 935 ms
53,264 KB
testcase_72 AC 925 ms
53,268 KB
testcase_73 AC 936 ms
53,272 KB
testcase_74 AC 947 ms
53,264 KB
testcase_75 AC 792 ms
53,212 KB
testcase_76 AC 800 ms
53,208 KB
testcase_77 AC 805 ms
53,208 KB
testcase_78 AC 951 ms
53,272 KB
testcase_79 AC 951 ms
53,260 KB
testcase_80 AC 908 ms
53,280 KB
testcase_81 AC 932 ms
53,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# scipy.sparse.csgraph.maximum_flow は現在32bit整数型しか扱えない 想定WA
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import maximum_flow

N, M, K = map(int, input().split())

A = [-1] * M
B = [-1] * M
C = [-1] * M
D = [-1] * M

c2i = []
for i in range(M):
    A[i], B[i], C[i], D[i] = map(int, input().split())
    c2i.append((C[i], i))
c2i.sort()

X = [0] * M

for ci, i in c2i:
    mf = [[0] * (N + 2) for _ in range(N + 2)]
    mf[0][A[i]] += K * N
    mf[0][B[i]] += K * N
    for a, b, x in zip(A, B, X):
        mf[0][a] += x
        mf[a][b] += x
    for j in range(N):
        mf[j + 1][N + 1] += K
    X[i] = min(D[i], round(maximum_flow(csr_matrix(mf), 0, N + 1).flow_value) - K - sum(X))

if sum(X) < K * (N - 1):
    print(-1)
else:
    print(sum([c * x for c, x in zip(C, X)]))
0