Uva 6437 - Power Plant 裸最小生成树
2013-12-01 22:49
253 查看
题意:
一个无向图中(至多100个点),..每条边有其费用...有些点是发电站..现在要求所有的点都可以达到至少一个发电站..所需的最小费用..
题解:
先就把发电站的点放到一个集合中..然后裸的kruskal了...
Program:
一个无向图中(至多100个点),..每条边有其费用...有些点是发电站..现在要求所有的点都可以达到至少一个发电站..所需的最小费用..
题解:
先就把发电站的点放到一个集合中..然后裸的kruskal了...
Program:
#include <iostream> #include <stdio.h> #include <algorithm> #include <string.h> #include <cmath> #define MAXN 205 using namespace std; struct node { int u,v,d; }edge[MAXN*MAXN]; int father[MAXN]; int getfather(int x) { if (father[x]==x) return x; return father[x]=getfather(father[x]); } bool cmp(node a,node b) { return a.d<b.d; } int main() { int C,cases,N,K,M,i,u,v,f,ans; scanf("%d",&C); for (cases=1;cases<=C;cases++) { scanf("%d%d%d",&N,&M,&K); for (i=1;i<=N;i++) father[i]=i; scanf("%d",&f); for (i=2;i<=K;i++) scanf("%d",&u),father[u]=f; for (i=1;i<=M;i++) scanf("%d%d%d",&edge[i].u,&edge[i].v,&edge[i].d); sort(edge+1,edge+1+M,cmp); ans=0; for (i=1;i<=M;i++) { u=edge[i].u,v=edge[i].v; if (getfather(u)==getfather(v)) continue; ans+=edge[i].d; father[father[u]]=father[v]; } printf("Case #%d: %d\n",cases,ans); } return 0; }
相关文章推荐
- uva 6437 - Power Plant【最小生成树】
- UVA Live 6437 Power Plant 最小生成树
- UVA Live 6437 Power Plant 最小生成树
- UVALive 6437 Power Plant 【最小生成树 + 思维】
- LA 6437 Power Plant (prim最小生成树)
- LA 6437 Power Plant (prim最小生成树)
- uva 10034 Freckles(最小生成树Kruskal)
- UVALive 4872 Underground Cables 最小生成树
- UVA - 11354Bond最小生成树,LCA寻找近期公共祖先
- (beginer) 最小生成树 UVA 10600 ACM Contest and Blackout
- uva 10453 Make Palindrome(dp,最小回文生成)
- UVALive 3887 边权极差最小生成树模板
- uva 10453 Make Palindrome(区间DP->回文字符串的最小生成)
- uva1395 枚举不同区间的最小生成树
- uva 1151 - Buy or Build poj 2784 Buy or Build(最小生成树)
- 2349 poj &&uva 10369 Arctic Network【最小生成树】
- uva 1395 Slim Span[最小生成树]
- uva 1151 Buy or Build (最小生成树)
- (beginer) 最小生成树 UVA 11747 Heavy Cycle Edges
- UVA - 10307 Killing Aliens in Borg Maze(最小生成树kruskal+bfs)