結果

問題 No.748 yuki国のお財布事情
ユーザー torikuminotorikumino
提出日時 2018-10-28 16:57:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,452 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 184,804 KB
最終ジャッジ日時 2023-08-12 08:05:44
合計ジャッジ時間 17,044 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,256 KB
testcase_01 AC 71 ms
71,344 KB
testcase_02 AC 73 ms
71,120 KB
testcase_03 AC 73 ms
71,312 KB
testcase_04 AC 73 ms
71,164 KB
testcase_05 AC 73 ms
71,368 KB
testcase_06 AC 71 ms
71,300 KB
testcase_07 AC 74 ms
71,312 KB
testcase_08 AC 72 ms
71,336 KB
testcase_09 AC 73 ms
71,100 KB
testcase_10 AC 70 ms
71,208 KB
testcase_11 AC 72 ms
71,296 KB
testcase_12 AC 72 ms
71,296 KB
testcase_13 AC 239 ms
87,440 KB
testcase_14 AC 358 ms
96,168 KB
testcase_15 AC 259 ms
88,244 KB
testcase_16 AC 565 ms
113,048 KB
testcase_17 AC 1,062 ms
151,244 KB
testcase_18 AC 1,290 ms
159,684 KB
testcase_19 AC 1,452 ms
184,804 KB
testcase_20 AC 1,316 ms
177,412 KB
testcase_21 AC 1,252 ms
163,556 KB
testcase_22 AC 73 ms
71,148 KB
testcase_23 AC 73 ms
71,264 KB
testcase_24 AC 72 ms
71,148 KB
testcase_25 AC 842 ms
136,300 KB
testcase_26 AC 1,267 ms
167,260 KB
testcase_27 AC 1,159 ms
164,924 KB
testcase_28 AC 1,036 ms
149,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m,k=map(int,input().split())
g = [{} 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 r.items() 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)
0