import sys N = 101 inf = 0x3f3f3f3f def prim(n, m, mapp): vis = [False] * N dis = [inf] * N sum_val = 0 for i in range(1, n + 1): dis[i] = mapp[1][i] vis[1] = True dis[1] = 0 for i in range(1, n): minn = inf u = 0 for j in range(1, n + 1): if not vis[j] and dis[j] < minn: minn = dis[j] u = j vis[u] = True sum_val += minn for j in range(1, n + 1): if not vis[j] and mapp[u][j] < dis[j]: dis[j] = mapp[u][j] return sum_val if __name__ == '__main__': n, m = map(int, input().split()) mapp = [[inf] * N for _ in range(N)] ss = 0 for _ in range(m): a, b, c = map(int, input().split()) mapp[a][b] = mapp[b][a] = c ss += c result = prim(n, m, mapp) print(ss - result)
0.0分
1 人评分
点我有惊喜!你懂得!浏览:1437 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:654 |
时间转换 (Java代码)浏览:617 |
C语言程序设计教程(第三版)课后习题9.3 (Java代码)浏览:1025 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:643 |
淘淘的名单 (C语言代码)答案错误???浏览:624 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:827 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:790 |
字符串的输入输出处理 (C语言代码)浏览:1019 |
校门外的树 (C语言代码)浏览:988 |