![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ACM并查集
桑榆207
在最终的结果到来之前,任何肯定会赢之类的话都是虚无缥缈的。
展开
-
并查集基础
代码:找根函数:int pre[1000 ];int find(int x) //查找根节点{ int r=x; while ( pre[r] != r ) //返回根节点 r r=pre[r]; int i=...原创 2018-09-29 17:45:57 · 147 阅读 · 0 评论 -
POJ1988Cube Stacking 并查集路径压缩
http://poj.org/problem?id=1988#include<cstdio>#include<cstring>using namespace std;const int MAXN=30000+100;int F[MAXN];//F[i]表示i节点的父节点int v[MAXN];//v[i]表从i到其父节点有多少个节点(包括父节点)int t...原创 2018-11-28 11:41:38 · 194 阅读 · 0 评论 -
POJ 2524无向图联通分量+并查集
POJ 2524 Ubiquitous Religions世界上宗教何其多。假设你对自己学校的学生总共有多少种宗教信仰很感兴趣。学校有n个学生,但是你不能直接问学生的信仰,不然他会感到很不舒服的。有另外一个方法是问m对同学,是否信仰同一宗教。根据这些数据,相信聪明的你是能够计算学校最多有多少种宗教信仰的。(好,不罗嗦那么多了) 解题思路---->显然并查集了。并查集的详细解释在可以点击 ...原创 2018-12-01 10:02:52 · 231 阅读 · 0 评论 -
POJ2493 A Bug's Life并查集看是否出现了环
http://poj.org/problem?id=2492DescriptionBackground Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they...原创 2018-12-03 21:16:14 · 238 阅读 · 0 评论 -
HDU5606 并查集变形转化思想
http://acm.hdu.edu.cn/showproblem.php?pid=5606//将权值为0的点uni()起来,形成并查集Problem DescriptionThere is a tree(the tree is a connected graph which contains n points and n−1 edges),the points are labeled...原创 2019-01-14 20:45:08 · 137 阅读 · 0 评论 -
HDU5438 Ponds 并查集+拓扑排序思想
http://acm.hdu.edu.cn/showproblem.php?pid=5438 Problem Description Betty owns a lot of ponds, some of them are connected with other ponds by pipes, and there will not be more than one pipe be...原创 2019-01-21 21:44:56 · 223 阅读 · 0 评论 -
带权并查集
N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three groups (it is possible that some group is empty). You don’t kn...原创 2019-02-18 21:16:40 · 88 阅读 · 0 评论 -
欧拉通路 字典树标号+并查集
You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straight line such that the colors of the endpoints that touch a...原创 2019-02-24 23:25:30 · 161 阅读 · 0 评论 -
并查集 JAVA
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the n...原创 2019-02-20 10:39:05 · 267 阅读 · 0 评论 -
并查集 JAVA
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to s...原创 2019-02-20 10:40:23 · 274 阅读 · 0 评论 -
并查集 逆向思考
In order to strengthen the defense ability, many stars in galaxy allied together and built many bidirectional tunnels to exchange messages. However, when the Galaxy War began, some tunnels were destro...原创 2019-02-20 20:48:57 · 194 阅读 · 0 评论 -
带权并查集 离散化思想 并查集路径方向
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the n...原创 2019-02-20 21:53:02 · 143 阅读 · 0 评论 -
CF图论一--Learning Languages--并查集
C. Learning Languagestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe "BerCorp" company has gotnemployees. These employees ...原创 2019-07-20 14:10:20 · 193 阅读 · 0 评论 -
CF图论一--Roads not only in Berland--思维+并查集
D. Roads not only in Berlandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland Government decided to improve relations with...原创 2019-07-30 09:21:40 · 154 阅读 · 0 评论 -
POJ1456 supermarket贪心+并查集优化
http://poj.org/problem?id=1456A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time uni...原创 2018-11-28 10:37:52 · 155 阅读 · 0 评论 -
ZJU3321 CIRCLE 并查集判断是否为环
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3321所有点度数为2且图联通是充要条件#include<cstdio>#include<cstring>using namespace std;const int maxn=50+5;int n,m;int degree[maxn]...原创 2018-11-28 10:01:30 · 115 阅读 · 0 评论 -
hdu1232并查集基础
Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( < 1000 )和道...原创 2018-09-29 18:32:47 · 162 阅读 · 0 评论 -
并查集加记录个数
poj1611输入n个学生m个集合,每个集合前有一个数为k,为集合元素个数 每个集合的第一号为传染源,和它在一个集合 中的都为感染者,输出感染人数/*100 4 2 1 2 5 10 13 11 12 14 2 0 1 2 99 2 200 2 1 5 5 1 2 3 4 5 1 0 0 0*/#include<bits/stdc++.h>#de...原创 2018-09-29 20:09:52 · 358 阅读 · 0 评论 -
并查集基础模板
贴一个完整代码:这个程序用于统计n个人,m个两两关系的门派的个数以及每一个门派的人员数量。代码很简单。也很容易理解第一种办法及初始化方式:#include<iostream>#include<cstring>using namespace std;int n, m;//n个人,m个两两团伙,团伙之间存在传递性,即A<->B,B<->...原创 2018-05-03 23:15:38 · 96 阅读 · 0 评论 -
并查集算法1.1POJ 1611 The Suspects
#include<bits/stdc++.h>using namespace std;const int maxn=200000;int fa[maxn];int num[maxn];int findset(int x){ return fa[x]==-1?x:fa[x]=findset(fa[x]);//常用路径压缩}void binds(int u,int...原创 2018-11-12 10:29:45 · 99 阅读 · 0 评论 -
并查集之亲戚联通
#include<bits/stdc++.h>using namespace std;#define maxn 200001int father[maxn];int m,n,i,x,y,q;int find(int x){ if(father[x]!=x)return find(father[x]); else return x;//找根;//递归找寻最根点...原创 2018-05-02 18:35:37 · 158 阅读 · 0 评论 -
POJ2236Wireless Network并查集
http://poj.org/problem?id=2236没输入一个点时,都要进行合并处理;到最后才判断#include<iostream>#include<math.h>#include<stdio.h>#include<string.h>#include<math.h>#include<algorith...原创 2018-11-20 23:27:59 · 121 阅读 · 0 评论 -
并查集模板
#include<iostream>#include<math.h>#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;struct point{ int x; in...原创 2018-11-21 09:17:39 · 97 阅读 · 0 评论 -
POJ1611The Suspects并查集
http://poj.org/problem?id=1611#include<iostream>#include<math.h>#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;...原创 2018-11-21 09:46:30 · 82 阅读 · 0 评论 -
POJ1308 Is It A Tree? 并查集判断有向图是否为树
http://poj.org/problem?id=1308无环cnt=1#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <string>#include <iostream>#include ...原创 2018-11-21 11:23:35 · 206 阅读 · 0 评论 -
POJ1213How Many Tables并查集记录个数
http://acm.hdu.edu.cn/showproblem.php?pid=1213#include<iostream>#include<math.h>#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using...原创 2018-11-24 11:38:14 · 121 阅读 · 0 评论 -
POJ1182食物链带权重并查集
http://poj.org/problem?id=1182开三种情况1-n表示同类1+n-n+n表示吃谁2n+1-3n表示被谁吃d=1只需要判断1、b和吃c的2、b和被c吃的看他们若同属一并查集就为假此时需要合并的是1、吃b的和吃c的2、被b吃的和被c吃的3、c和bd=2只需要判断1、c和b吃的2、c和b 此时需要合并的是...原创 2018-11-24 19:56:04 · 145 阅读 · 0 评论 -
并查集+二分 POJ2253
http://poj.org/problem?id=2253reddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is ...原创 2018-11-30 11:41:21 · 216 阅读 · 0 评论 -
POJ1272小希的迷宫并查集+set
http://acm.hdu.edu.cn/showproblem.php?pid=1272 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小...原创 2018-12-02 18:52:42 · 185 阅读 · 0 评论 -
CF图论一-- Cthulhu--并查集判环和联通
B. Cthulhutime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output...Once upon a time a man came to the sea. The sea was stormy and dark...原创 2019-07-23 08:27:47 · 271 阅读 · 0 评论