HDU 1233 还是畅通工程 最小生成树 Prim模板的应用
来源:互联网 发布:排课表软件 编辑:程序博客网 时间:2024/06/06 13:58
Ice_cream's world ITime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1138 Accepted Submission(s): 684Problem Descriptionice_cream's world is a rich country, it has many fertile lands. Today, the queen of ice_cream wants award land to diligent ACMers. So there are some watchtowers are set up, and wall between watchtowers be build, in order to partition the ice_cream’s world. But how many ACMers at most can be awarded by the queen is a big problem. One wall-surrounded land must be given to only one ACMer and no walls are crossed, if you can help the queen solve this problem, you will be get a land.InputIn the case, first two integers N, M (N<=1000, M<=10000) is represent the number of watchtower and the number of wall. The watchtower numbered from 0 to N-1. Next following M lines, every line contain two integers A, B mean between A and B has a wall(A and B are distinct). Terminate by end of file.OutputOutput the maximum number of ACMers who will be awarded.One answer one line.Sample Input8 100 11 21 32 43 40 55 66 73 64 7Sample Output3AuthorWiskeySourceHDU 2007-10 Programming Contest_WarmUp
//作图后可以看出每有一条回路,就会有一块地被划分出#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;#define MAXN 100000*2int Par[MAXN], Rank[MAXN];void Init(int n){ for (int i = 1;i <= n;i++) { Par[i] = i; Rank[i] = 0; }}int Find(int x){ if (Par[x] == x) return x; else return Par[x] = Find(Par[x]); ///同时压缩路径}void Unite(int x, int y){ x = Find(x);y = Find(y); if (x == y) return; if (Rank[x]<Rank[y]) Par[x] = y; else Par[y] = x; if (Rank[x] == Rank[y]) Rank[x]++;}int main(void){ //freopen("F:\\test.txt","r",stdin); int N,M; while(~scanf("%d %d",&N,&M)) { Init(N);int Count = 0; for(int i=1,a,b;i<=M&&scanf("%d %d",&a,&b);i++) { if(Find(a+1)!=Find(b+1)) Unite(a+1,b+1); else Count++;//利用并查集判断是否有回路,自圈也是回路 } printf("%d\n",Count); }}
来源: http://acm.hdu.edu.cn/showproblem.php?pid=2120
0 0
- HDU 1233 还是畅通工程 最小生成树 Prim模板的应用
- hdu 1233 还是畅通工程(Prim最小生成树)
- hdu 1233 还是畅通工程--最小生成树prim
- HDU 1233 还是畅通工程---prim求最小生成树
- hdu 1233 还是畅通工程(最小生成树prim)
- hdu 1233 还是畅通工程 最小生成树prim
- HDU 1233 还是畅通工程 (最小生成树Prim)
- HDU 1233-还是畅通工程(经典的最小生成树, Kruskal和prim算法)
- HDU 还是畅通工程 -- 最小生成树prim
- Hud 1233 还是畅通工程[最小生成树Prim]
- HDOJ 1233 还是畅通工程 【最小生成树】+【prim】
- hdoj 1233 还是畅通工程【最小生成树 kruskal && prim】
- HDOJ 1233 还是畅通工程 最小生成树 kruskal && prim
- 【最小生成树+Prim】杭电 hdu 1233 还是畅通工程
- hdu 1233 还是畅通工程 最小生成树(prim算法 + kruskal算法)
- HDU--1233:还是畅通工程 (并查集 & 最小生成树Prim)
- HDU 1233 还是畅通工程(Prim求最小生成树)
- hdu 1233 还是畅通工程 (最小生成树,prim,优先队列,kruskal并查集)
- redis集群的合纵和连横
- [HDU 5739] Fantasia (点双联通分量 + Block Forest Data Structure)
- 快速排序算法的时间复杂度分析[详解Master method]
- linux命令link汇总
- spring技术框架基础知识三属性编辑器
- HDU 1233 还是畅通工程 最小生成树 Prim模板的应用
- yum方式安装ffmpeg步骤
- 3.8 编写一个程序打印如图 3.1 所示的 n 阶杨辉三角形,其中 n 由用户输入,该值不 能大于 13。
- ”The virtual device got no IP address.“的解决
- HDU1213 How Many Tables 并查集
- (菜鸟来动手-第四天)SSM整合之BaseService,BaseDao
- Java异常处理-----程序中的异常处理.启蒙
- 90. Subsets II
- 如何用PS将gif图背景变透明