結果

問題 No.748 yuki国のお財布事情
ユーザー torikuminotorikumino
提出日時 2018-10-28 16:46:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 784 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 10,840 KB
実行使用メモリ 817,052 KB
最終ジャッジ日時 2023-08-12 08:04:47
合計ジャッジ時間 8,821 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,224 KB
testcase_01 AC 16 ms
8,192 KB
testcase_02 AC 16 ms
8,256 KB
testcase_03 AC 15 ms
8,248 KB
testcase_04 AC 16 ms
8,232 KB
testcase_05 AC 16 ms
8,208 KB
testcase_06 AC 16 ms
8,236 KB
testcase_07 AC 16 ms
8,092 KB
testcase_08 AC 15 ms
8,172 KB
testcase_09 AC 15 ms
8,180 KB
testcase_10 AC 15 ms
8,208 KB
testcase_11 AC 16 ms
8,152 KB
testcase_12 AC 15 ms
8,176 KB
testcase_13 AC 191 ms
22,476 KB
testcase_14 TLE -
testcase_15 AC 374 ms
34,524 KB
testcase_16 MLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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[x] += s[y]
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)
0