結果
| 問題 | 
                            No.748 yuki国のお財布事情
                             | 
                    
| コンテスト | |
| ユーザー | 
                             torikumino
                         | 
                    
| 提出日時 | 2018-10-28 16:49:50 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 783 bytes | 
| コンパイル時間 | 754 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 1,097,692 KB | 
| 最終ジャッジ日時 | 2024-11-19 07:09:36 | 
| 合計ジャッジ時間 | 20,955 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 TLE * 1 MLE * 9 | 
ソースコード
n,m,k=map(int,input().split())
g = [['-']*n for _ in range(n)]
v=[]
for _ in range(m):
    i,j,c=map(int,input().split())
    g[i-1][j-1] = c
    g[j-1][i-1] = c
    v.append((c,i-1,j-1))
p = list(range(len(g)))
s = [1]*len(g)
def f(x):
    if x == p[x]:
        return x
    p[x] = f(p[x])
    return p[x]
def u(x, y):
    x = f(x)
    y = f(y)
    if s[x] > s[y]:
        x, y = y, x
    p[x] = p[y]
    s[y] += s[x]
e = {(int(c),i,j) for i,r in enumerate(g)
        for j,c in enumerate(r) if c != '-'}
pp =0
for _ in range(k):
    c,i,j=v[int(input())-1]
    e.remove((c,i,j))
    e.remove((c,j,i))
    e.add((0,i,j))
    e.add((0,j,i))
    pp += c
e = sorted(e)
r = 0
d = 0
for c,i,j in e:
    if f(i)==f(j):
        r += c
        continue
    u(i,j)
    d += c
print((r-d)//2)
            
            
            
        
            
torikumino