結果

問題 No.2200 Weird Shortest Path
ユーザー ああいいああいい
提出日時 2023-01-29 16:17:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 808 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 93,136 KB
最終ジャッジ日時 2023-09-11 23:51:36
合計ジャッジ時間 23,949 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,364 KB
testcase_01 AC 68 ms
71,356 KB
testcase_02 AC 66 ms
71,248 KB
testcase_03 AC 79 ms
75,104 KB
testcase_04 AC 101 ms
77,544 KB
testcase_05 AC 68 ms
71,312 KB
testcase_06 AC 70 ms
71,188 KB
testcase_07 AC 75 ms
75,280 KB
testcase_08 AC 101 ms
77,704 KB
testcase_09 AC 96 ms
76,884 KB
testcase_10 AC 70 ms
71,224 KB
testcase_11 AC 70 ms
71,412 KB
testcase_12 AC 70 ms
71,136 KB
testcase_13 AC 68 ms
71,060 KB
testcase_14 AC 68 ms
70,984 KB
testcase_15 AC 100 ms
76,980 KB
testcase_16 AC 70 ms
71,156 KB
testcase_17 AC 363 ms
82,688 KB
testcase_18 AC 533 ms
86,500 KB
testcase_19 AC 807 ms
91,740 KB
testcase_20 AC 782 ms
91,488 KB
testcase_21 AC 363 ms
83,048 KB
testcase_22 AC 508 ms
86,008 KB
testcase_23 AC 764 ms
92,556 KB
testcase_24 AC 254 ms
80,652 KB
testcase_25 AC 755 ms
91,812 KB
testcase_26 AC 793 ms
91,472 KB
testcase_27 AC 385 ms
83,996 KB
testcase_28 AC 624 ms
88,872 KB
testcase_29 AC 795 ms
92,772 KB
testcase_30 AC 769 ms
91,444 KB
testcase_31 AC 532 ms
86,132 KB
testcase_32 AC 791 ms
93,136 KB
testcase_33 AC 804 ms
92,212 KB
testcase_34 AC 789 ms
92,520 KB
testcase_35 AC 796 ms
92,932 KB
testcase_36 AC 802 ms
92,904 KB
testcase_37 AC 808 ms
92,204 KB
testcase_38 AC 790 ms
92,908 KB
testcase_39 AC 486 ms
85,724 KB
testcase_40 AC 487 ms
90,244 KB
testcase_41 AC 366 ms
83,128 KB
testcase_42 AC 483 ms
90,952 KB
testcase_43 AC 793 ms
91,812 KB
testcase_44 AC 775 ms
91,580 KB
testcase_45 AC 794 ms
91,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 8)


N,M = map(int,input().split())
edge = []
C = 20
mask = 1 << C
for _ in range(M):
    a,b,w = map(int,input().split())
    edge.append((w,(a << C) + b))
edge.sort()

ans = 0
parent = [-1] * N
def find(i):
    if parent[i] < 0:return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    if parent[I] < parent[J]:
        I,J = J,I
    parent[J] += parent[I]
    parent[I] = J
    return True
def isSame(i,j):
    return find(i) == find(j)
for w,k in edge:
    a = k // mask
    b = k % mask
    #print(w,a,b)
    a -= 1
    b -= 1
    A = find(a)
    B = find(b)
    if A == B:continue
    na = -parent[A]
    nb = -parent[B]
    ans += w * na * nb
    unite(a,b)
    #print(na,nb,w)
print(ans)
0