結果

問題 No.748 yuki国のお財布事情
ユーザー rookzenorookzeno
提出日時 2018-11-03 12:09:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 1,282 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 87,328 KB
実行使用メモリ 100,340 KB
最終ジャッジ日時 2023-08-13 02:13:24
合計ジャッジ時間 9,365 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,396 KB
testcase_01 AC 69 ms
71,144 KB
testcase_02 AC 69 ms
71,264 KB
testcase_03 AC 68 ms
71,336 KB
testcase_04 AC 68 ms
71,200 KB
testcase_05 AC 70 ms
71,136 KB
testcase_06 AC 69 ms
71,300 KB
testcase_07 AC 70 ms
70,932 KB
testcase_08 AC 71 ms
71,372 KB
testcase_09 AC 70 ms
71,132 KB
testcase_10 AC 70 ms
71,372 KB
testcase_11 AC 72 ms
71,136 KB
testcase_12 AC 71 ms
71,348 KB
testcase_13 AC 156 ms
79,912 KB
testcase_14 AC 214 ms
82,936 KB
testcase_15 AC 168 ms
80,260 KB
testcase_16 AC 286 ms
87,152 KB
testcase_17 AC 441 ms
97,920 KB
testcase_18 AC 478 ms
98,748 KB
testcase_19 AC 506 ms
99,416 KB
testcase_20 AC 446 ms
97,288 KB
testcase_21 AC 483 ms
100,340 KB
testcase_22 AC 71 ms
71,272 KB
testcase_23 AC 70 ms
71,272 KB
testcase_24 AC 70 ms
71,328 KB
testcase_25 AC 272 ms
94,816 KB
testcase_26 AC 427 ms
98,144 KB
testcase_27 AC 392 ms
97,420 KB
testcase_28 AC 295 ms
91,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m,k = map(int,input().split())
a = []
for i in range(m):
  x,y,z = map(int,input().split())
  a.append([x-1,y-1,z])
c = [int(input())for i in range(k)]
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]

    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] != self.table[s2]:
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                self.table[s1] += -1
                self.table[s2] = s1
        return
gra = []
uc = 0
ans = 0
for i in range(m):
  ans += a[i][2]
hissu = []
uni = UnionFind(n)
for i in c:
  hissu.append(a[i-1])
for i in range(k):
  hen = hissu[i]
  if (uni.find(hen[0]) != uni.find(hen[1])):
    uc += 1
  ans -= hen[2]
  uni.union(hen[0],hen[1])
for i in range(m):
  gra.append(a[i])
gra = sorted(gra, key = lambda x: x[2])
for i in range(len(gra)):
  hen = gra[i]
  if (uni.find(hen[0]) != uni.find(hen[1])):
    ans -= hen[2]
    uni.union(hen[0],hen[1])
    uc += 1
  if uc == n-1:
    break
print(ans)
0