UVALive 6807(最大生成树)
来源:互联网 发布:网络教学有什么特点 编辑:程序博客网 时间:2024/06/06 10:04
解题思路:求最大生成树, 不在最大生成树上的边即为所求。
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;struct tt{ int from; int to; int w; bool operator <(tt p1) const{ return w > p1.w; }}a[100010];int p[10010];int vis[100010];int find(int x){ return x == p[x] ? x : p[x] = find(p[x]);}int main(){ int T, kase = 0; scanf("%d", &T); while(T--){ int n, m; scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) p[i] = i; for(int i = 1; i <= m; i++){ scanf("%d%d%d", &a[i].from, &a[i].to, &a[i].w); } sort(a + 1, a + m + 1); memset(vis, 0, sizeof vis); int cnt = n; for(int i = 1; i <= m; i++){ int t1 = find(a[i].from); int t2 = find(a[i].to); if(t1 != t2){ p[t1] = t2; vis[i] = 1; if(--cnt == 1) break; } } int ans = 0, maxx = 0; for(int i = 1; i <= m; i++){ if(!vis[i]){ ans += a[i].w; maxx = max(a[i].w, maxx); } } printf("Case #%d: %d %d\n", ++kase, ans, maxx); }}
0 0
- UVALive 6807(最大生成树)
- UVaLive/LA 6807 Túnel de Rata(最大生成树)
- UVALive 6807 Túnel de Rata (最大生成树)
- UVALive 6837 (最小生成树)
- 曼哈顿最小距离生成树(poj 3241&& UVALive 3662)
- UVALive 6437 Power Plant(最小生成树)
- UVAlive 6622 Absurdistan Roads(最小生成树+LCA)
- UVALive 6851The Programmers(最大流)
- UVALive 3645 Objective: Berlin(最大流)
- aoj2224(最大生成树)
- UVALive - 4960 Sensor network(生成树+LCA)
- UVALive - 7303 Aquarium(最小生成树)
- UVALive 7303Aquarium 最小生成树
- UVaLive 3938 "Ray, Pass me the dishes!" (线段树求动态最大连续和)
- UVALIVE 4819 最大流
- uvalive 最大子矩阵
- UVALive 2957 Bring Them There(拆点+最大流)
- UVALive 5220 Internet Bandwidth(最大流,模板题)
- linphone呼叫流程分析
- mysql主从复制配置
- BZOJ1111——[POI2007]四进制的天平Wag
- mac启动apache 报错“httpd-mpm.conf:”
- IPU总结笔记
- UVALive 6807(最大生成树)
- 二部图最大匹配
- Spring框架中使用注解
- 深度学习笔记9:权值更新的实现
- HPU图论专项(graph)【拓扑--二分图--最小生成树---树的直径---并查集--奇偶树---最小环---强联通】
- C语言内存分配
- Java中ArrayList和LinkedList区别
- SVN数据迁移
- 使用Java开发高性能网站需要关注的那些事儿