![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
并查集
nextcy
我是一个热爱程序的人,希望大家一起努力。
展开
-
HDU 1232
<br />题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1232<br />题意就不要我多说了;赤裸裸的一道并查集。保存各点的父亲节点。最后那些父亲还是本身的点就是要加进来的。道路的数目就是点减去1.<br />然后是输出。贴上一点代码。<br />#include <stdio.h> #include <string.h> //using namespace std; int n,m,father[1001],sum[1001],ans; vo原创 2010-07-30 13:42:00 · 497 阅读 · 0 评论 -
HDU 1272
<br />http://acm.hdu.edu.cn/showproblem.php?pid=1272<br />题意:判断一个迷宫是否存在多条从i点到j点的路径。<br />解法:并查集。<br />#include <iostream> #include <cstring> using namespace std; int father[100001],v[100001]; void init() { int i; for(i=0;i<=100000;i++) f原创 2010-07-30 13:45:00 · 372 阅读 · 0 评论 -
HDU 3371 并查集
<br />http://acm.hdu.edu.cn/showproblem.php?pid=3371<br />题意:给你一些分开的城市群,还给你一些城市相连的权值。让你求将所有城市相连所需的最小权值,不肯能输出-1.<br />解法:并查集。<br />#include <iostream> #include <algorithm> using namespace std; int n,m,k,father[501],ans; struct node { int u,v,c; }原创 2010-08-07 20:28:00 · 370 阅读 · 0 评论 -
HDU 2473 并查集
<br />http://acm.hdu.edu.cn/showproblem.php?pid=2473<br />其实这题不用删点,只要增加一个点即可。<br />#include <iostream> using namespace std; const int M=1100000; int n,m,father[M],rank[M],id[M],ans; char s[5]; void init() { for(int i=0;i<M;i++) father[i]=i,ra原创 2010-08-07 20:30:00 · 564 阅读 · 0 评论 -
HDU 1856 并查集+离散化
<br />http://acm.hdu.edu.cn/showproblem.php?pid=1856<br />其实点最多只有200000个,在这里就可以进行离散化。<br />#include <iostream> #include <cstdio> #include <cstring> using namespace std; int n,father[10000001],rank[10000001],ans,sum,v[10000001],st[200001]; int max(int原创 2010-08-07 20:32:00 · 698 阅读 · 0 评论