結果

問題 No.2200 Weird Shortest Path
ユーザー hiryuNhiryuN
提出日時 2023-01-29 16:43:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,124 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 113,944 KB
最終ジャッジ日時 2023-09-12 00:08:04
合計ジャッジ時間 29,828 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,168 KB
testcase_01 AC 75 ms
71,068 KB
testcase_02 AC 77 ms
71,168 KB
testcase_03 AC 93 ms
76,104 KB
testcase_04 AC 121 ms
78,140 KB
testcase_05 AC 74 ms
71,064 KB
testcase_06 AC 82 ms
71,240 KB
testcase_07 AC 89 ms
75,740 KB
testcase_08 AC 119 ms
78,040 KB
testcase_09 AC 135 ms
77,864 KB
testcase_10 AC 92 ms
71,168 KB
testcase_11 AC 90 ms
71,064 KB
testcase_12 AC 93 ms
71,352 KB
testcase_13 AC 76 ms
71,272 KB
testcase_14 AC 74 ms
71,128 KB
testcase_15 AC 113 ms
78,076 KB
testcase_16 AC 78 ms
71,240 KB
testcase_17 AC 401 ms
88,024 KB
testcase_18 AC 620 ms
97,688 KB
testcase_19 AC 1,031 ms
108,244 KB
testcase_20 AC 1,018 ms
110,032 KB
testcase_21 AC 454 ms
91,332 KB
testcase_22 AC 575 ms
94,524 KB
testcase_23 AC 1,064 ms
111,120 KB
testcase_24 AC 257 ms
83,516 KB
testcase_25 AC 1,049 ms
108,824 KB
testcase_26 AC 1,045 ms
110,016 KB
testcase_27 AC 399 ms
90,340 KB
testcase_28 AC 766 ms
102,264 KB
testcase_29 AC 1,052 ms
111,624 KB
testcase_30 AC 1,019 ms
109,788 KB
testcase_31 AC 648 ms
97,232 KB
testcase_32 AC 1,052 ms
113,344 KB
testcase_33 AC 1,068 ms
113,396 KB
testcase_34 AC 1,041 ms
113,304 KB
testcase_35 AC 1,074 ms
113,776 KB
testcase_36 AC 1,067 ms
113,284 KB
testcase_37 AC 1,062 ms
113,272 KB
testcase_38 AC 1,072 ms
113,944 KB
testcase_39 AC 553 ms
98,872 KB
testcase_40 AC 698 ms
112,140 KB
testcase_41 AC 495 ms
96,048 KB
testcase_42 AC 712 ms
112,196 KB
testcase_43 AC 1,124 ms
112,936 KB
testcase_44 AC 1,097 ms
112,924 KB
testcase_45 AC 1,107 ms
113,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(a):
    b=a
    a=A[a]
    while type(a)!=int:
        b=int(a)
        a=A[int(a)]
    return [a,b]
n,m=map(int,input().split())
D=[]
A=[None]+[1]*n
for i in range(1,m+1):
    a,b,w=map(int,input().split())
    D.append([w,a,b])
D.sort()
D=[None]+D
ans=0
for i in range(1,m+1):
    q=f(D[i][1])
    w=f(D[i][2])
    if q[1]==w[1]:
        div=0
    else:
        div=q[0]*w[0]
        if A[q[1]]>A[w[1]]:
            A[q[1]]+=A[w[1]]
            A[w[1]]=str(q[1])
        else:
            A[w[1]]+=A[q[1]]
            A[q[1]]=str(w[1])
    ans+=D[i][0]*div
print(ans)
0