并查集
小魚兒.
天下皆白,唯我独黑!
展开
-
PAT A1021 Deepest Root (25 分)(10.3 判断给定图是否为树,并求最大高度,输出最大高度时的根结点)
1021 Deepest Root (25 分) A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a ...原创 2019-10-29 15:19:09 · 133 阅读 · 0 评论 -
PAT A10.4 1013 Battle Over Cities (25 分)(求删除结点后所需增加边数是图连通——求连通分量数)
1013 Battle Over Cities (25 分) It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We...原创 2019-10-28 15:07:11 · 130 阅读 · 0 评论 -
9.6并查集基础知识
#include <csdio> #include <algorithm> using namespace std; //并查集——集合的查、并 //1初始化 //一开始,每个元素都是独立的一个集合,因此需令所有的father[i]=i; int father[1122];//father[i]表示元素i的父亲结点 for(int i=1;i<=N;++i) ...原创 2019-10-24 16:05:47 · 131 阅读 · 0 评论 -
PAT A1107 Social Clusters (30 分)(并查集的应用)
1107 Social Clusters (30 分) When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of...原创 2019-10-21 14:55:57 · 117 阅读 · 0 评论 -
Code Up 9.6问题 D: More is better(并查集的应用)
问题 D: More is better 题目描述 Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain require...原创 2019-10-20 16:52:16 · 165 阅读 · 0 评论 -
Code Up 9.6问题 C: How Many Tables(并查集的应用)
问题 C: How Many Tables 题目描述 Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not al...原创 2019-10-20 15:33:55 · 167 阅读 · 0 评论 -
Code Up 9.6问题 B: 畅通工程(并查集应用)
问题 B: 畅通工程 题目描述 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路? 输入 测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( < 1000 )和道路数目M...原创 2019-10-20 15:14:44 · 217 阅读 · 0 评论 -
Code Up 9.6问题 A: 通信系统(并查集的应用)
问题 A: 通信系统 题目描述 某市计划建设一个通信系统。按照规划,这个系统包含若干端点,这些端点由通信线缆链接。消息可以在任何一个端点产生,并且只能通过线缆传送。每个端点接收消息后会将消息传送到与其相连的端点,除了那个消息发送过来的端点。如果某个端点是产生消息的端点,那么消息将被传送到与其相连的每一个端点。 为了提高传送效率和节约资源,要求当消息在某个端点生成后,其余各个端点均能接收到...原创 2019-10-19 15:55:05 · 224 阅读 · 0 评论