随笔分类 - 数据结构---并查集
摘要:题目链接:https://www.dotcpp.com/oj/problem1744.html 题目描述 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即
阅读全文
摘要:1 #include 2 using namespace std; 3 #define MAX_N 1000 4 int par[MAX_N]; 5 int ranks[MAX_N]; 6 7 //初始化n个元素 8 void init(int n) 9 { 10 for(int i=0;i<n;i++){ 11 par[i]=i; 12 ...
阅读全文
摘要:题目链接:http://poj.org/problem?id=1789 Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other f
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3461 A lock you use has a code system to be opened instead of a key. The lock contains a sequence of wh
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always
阅读全文
摘要:These days, you can do all sorts of things online. For example, you can use various websites to make virtual friends. For some people, growing their s
阅读全文
摘要:上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 int f[1000010]; 5 int sum[1000010]; 6 int find(int x) 7 { 8 if(x!=f[x]) 9 { 10 int pre=f[x];//pre是x的一个父节点。 11 f[x]=find...
阅读全文
摘要:N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树。 N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树。 Input 第1行:2个数N,M中间用空格分隔,N为点的数量,M为边的数量。(2 <= N <= 1000, 1 <= M <= 50000) 第2 - M + 1行:
阅读全文
摘要:省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。现得到城镇道路统计表,表中列出了任意两城镇间修建道路的费用,以及该道路是否已经修通的状态。现请你编写程序,计算出全省畅通需要的最低成本。 Input测试输入包含若干测试用例。每个
阅读全文
摘要:某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。 Input测试输入包含若干测试用例。每个测试用例的第1行给出
阅读全文
摘要:动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同类。 第二种说
阅读全文
摘要: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
阅读全文
摘要:Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize
阅读全文
摘要:某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路? Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数
阅读全文
摘要:Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that
阅读全文