
并查集
淡蓝色的狼
这个作者很懒,什么都没留下…
展开
-
并查集
畅通工程简单并查集的应用,模板题#include<iostream>#include<cstdio>using namespace std;int pre[1100];int findd(int x){ int r=x; while(r!=pre[r]) { r=pre[r]; } int i=x,j; while(i!=r)原创 2017-07-18 11:04:10 · 163 阅读 · 0 评论 -
A - Frogger
Freddy 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 dirty and full of tourists’ suns原创 2017-09-25 21:00:52 · 304 阅读 · 0 评论 -
nyoj 711 最舒适的路线
基础并查集+枚举 题目链接<-点击最舒适的路线 时间限制:5000 ms | 内存限制:65535 KB 难度:5 描述 异形卵潜伏在某区域的一个神经网络中。其网络共有N个神经元(编号为1,2,3,…,N),这些神经元由M条通道连接着。两个神经元之间可能有多条通道。异形卵可以在这些通道上来回游动,但在神经网络中任一条通道的游动速度必须是一定的。当然异形卵不希望从一条通原创 2017-08-28 17:29:55 · 726 阅读 · 0 评论 -
hdoj 1856 More is better 【并查集 求最大节点数】
求最大节点数即可详细见代码: hdoj 1856 More is better 【并查集 求最大节点数】#include<iostream>#include<cstdio>#include<cstring>using namespace std;int pre[10000000+100];int vis[10000000+100];int sum=0;void init(int n)原创 2017-08-26 16:19:12 · 250 阅读 · 0 评论 -
hdoj 2120 Ice_cream's world I 【并查集判断成环数】
并查集判断环数,裸题 代码如下: hdoj 2120 Ice_cream's world I 【并查集判断成环数】#include<iostream>#include<cstring>#include<cstdio>using namespace std;int pre[1100],sum=0;void init(int n){ int i; for(i=0;i<=原创 2017-08-26 15:31:22 · 268 阅读 · 0 评论 -
hdoj 1325 Is It A Tree?
此题满足条件:1,不成环(包括自环);2,任何点入度不能超过1; 注意输入两数为负数结束代码如下:#include<iostream> #include<cstdio>#include<cstring>#include<algorithm>using namespace std;int pre[1100],vis[1100],aa[1100];int findd(int x){原创 2017-08-26 15:16:43 · 253 阅读 · 0 评论 -
NYoj42 一笔画问题
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来。规定,所有的边都只能画一次,不能重复画。输入 第一行只有一个正整数N(N<=10)表示测试数据的组数。 每组测试数据的第一行有两个正整数P,Q(P<=1000,Q<=2000),分别表示这个原创 2017-08-25 21:45:33 · 228 阅读 · 0 评论 -
食物链 POJ - 1182
题目链接<-点击动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。 有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是”1 X Y”,表示X和Y是同类。 第二种说法是”2 X Y”,表示X吃Y。 此人对N个动物,用上述两种说法,原创 2017-08-25 21:08:04 · 174 阅读 · 0 评论 -
并查集
我从这里转载,那人也是转载,出处不明,请原作者见谅 并查集是我暑假从高手那里学到的一招,觉得真是太精妙的设计了。以前我无法解决的一类问题竟然可以用如此简单高效的方法搞定。不分享出来真是对不起party了。(party:我靠,关我嘛事啊?我跟你很熟么?) 来看一个实例,杭电1232畅通工程 首先在地图上给你若干个城镇,这些城镇都可以看作点,然后告诉你哪些对城镇之间是有道路直接相连的。最后要解决的转载 2017-07-22 10:37:47 · 223 阅读 · 0 评论 -
Mahmoud and a Dictionary CodeForces - 766D
Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two word原创 2017-10-30 21:59:58 · 452 阅读 · 0 评论