![](https://img-blog.csdnimg.cn/20190927151101105.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
最小生成树
穷源溯流
路很长,尽管走便是。
展开
-
HDU 1102 Constructing Roads(Prim)
分别给出 i->j 的价格,给出 m 条路已经建好,求最小连接费用const int N=100+5; int n,m,t; int i,j,k; int f[N][N]; int minn[N]; bool vis[N];void Prim(int s){ int ans=0; for(int i=1;i<=n;i++){ vis[i]=0; minn[i]=f[s][i]; ...原创 2020-08-05 23:47:28 · 208 阅读 · 0 评论 -
HDU 5624 KK‘s Reconstruction(Kruskal)
给出 n,m,再给出 m 条边,求 n 个点连起来时,(最大值 - 最小值)的最小值是多少const int N=2e5+5; int n,m,t; int i,j,k; int fa[N];struct node{ int u,v; int w; bool operator<(node b){ if(w!=b.w) return w<b.w; if(u!=b.u) return u<b...原创 2020-08-05 21:42:07 · 311 阅读 · 0 评论 -
HDU 1879 继续畅通工程(Kruskal)
const int N=1e4+5; int n,m,t; int i,j,k; int fa[N];struct node{ int u,v; int w; bool operator<(node b){ if(w!=b.w) return w<b.w; if(u!=b.u) return u<b.u; return v<b.v; }}G[N];int Fi...原创 2020-08-05 21:25:46 · 250 阅读 · 0 评论 -
畅通工程再续(Kruskal)
const int N=1e4+5; int n,m,t; int i,j,k; int fa[N];struct node{ int u,v; double w; bool operator<(node b){ if(w!=b.w) return w<b.w; if(u!=b.u) return u<b.u; return v<b.v; }}G[N];int...原创 2020-08-05 20:27:03 · 456 阅读 · 0 评论 -
HDU 1863 畅通工程(Kruskal)
const int N=2e5+5; int n,m,t; int i,j,k; int fa[N];struct node{ int u,v,w; bool operator<(node b){ if(w!=b.w) return w<b.w; if(u!=b.u) return u<b.u; return v<b.v; }}G[N];int Find(int x)...原创 2020-08-05 19:48:18 · 182 阅读 · 0 评论 -
POJ 3522 Slim Span(Kruskal)
有 n 个点,m 条边,求 n 个点连接起来时最大边与最小边差的最小值按照边的权值进行排序,这样只需要遍历每 n-1 条边,寻找出答案即可const int N=2e5+5; int n,m,t; int i,j,k; int fa[N];struct node{ int u,v,w;}G[N];bool cmp(node a,node b){ if(a.w!=b.w) return a.w<b.w; if(a.u...原创 2020-08-05 17:34:46 · 195 阅读 · 0 评论 -
HDU 6187 Destroy Walls(最大生成树+Kruskal)
给出 n 个城市的坐标 xi,yi,有 m 个城墙,第 ui 个城市和第 vi 个城市之间是一道城墙,破坏该城墙需要 wi 的花费,问使得整个图中无环的最小花费向反方向考虑,使得剩余城墙数量尽量的多,且剩余城墙破坏价值尽量的大,求该图的最大生成树const int N=2e5+5; int n,m,t; int i,j,k; int fa[N];struct node{ int u,v,w; bool operator...原创 2020-08-05 15:14:19 · 221 阅读 · 0 评论 -
Jungle Roads
The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to maintain....原创 2020-05-14 16:00:03 · 205 阅读 · 0 评论 -
The Suspects
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 separate the suspects from others.In the Not-Spreadin...原创 2020-05-14 15:31:40 · 255 阅读 · 0 评论 -
Eddy's picture (kruskal)
Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result it can be imagined, the ...原创 2020-05-14 14:59:03 · 230 阅读 · 0 评论 -
Constructing Roads(并查集)
There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if there is a road between A and B, or there exists a villag原创 2020-05-13 18:32:36 · 361 阅读 · 0 评论 -
1351:家谱树
【题目描述】 有个人的家族很大,辈分关系很混乱,请你帮整理一下这种关系。 给出每个人的孩子的信息。 输出一个序列,使得每个人的后辈都比那个人后列出。 【输入】 第1行一个整数N(1≤N≤100),表示家族的人数; 接下来N行,第I行描述第I个人的儿子; 每行最后是0表示描述完毕。 【输出】 输出一个序列,使得每个人的...原创 2020-04-28 12:05:52 · 743 阅读 · 0 评论 -
1393:联络员(liaison)
【题目描述】 Tyvj已经一岁了,网站也由最初的几个用户增加到了上万个用户,随着Tyvj网站的逐步壮大,管理员的数目也越来越多,现在你身为Tyvj管理层的联络员,希望你找到一些通信渠道,使得管理员两两都可以联络(直接或者是间接都可以)。Tyvj是一个公益性的网站,没有过多的利润,所以你要尽可能的使费用少才可以。 目前你已经知道,Tyvj的通信渠道分为两大类,一类是必选通信渠...原创 2020-04-27 11:08:15 · 740 阅读 · 0 评论 -
1392:繁忙的都市(city)
【题目描述】 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造。城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条道路相连接。这些道路是双向的,且把所有的交叉路口直接或间接的连接起来了。每条道路都有一个分值,分值越小表示这个道路越繁忙,越需要进行改造。但是市政府的资金有限,市长希望进行改造的道...原创 2020-04-27 10:45:22 · 798 阅读 · 0 评论 -
1391:局域网(net)
【题目描述】 某个局域网内有n(n≤100)台计算机,由于搭建局域网时工作人员的疏忽,现在局域网内的连接形成了回路,我们知道如果局域网形成回路那么数据将不停的在回路内传输,造成网络卡的现象。因为连接计算机的网线本身不同,所以有一些连线不是很畅通,我们用f(i,j)表示i,j之间连接的畅通程度(f(i,j)≤1000),f(i,j)值越小表示i,j之间连接越通畅,f(i,j)为0表示...原创 2020-04-27 10:41:58 · 923 阅读 · 0 评论 -
1348:城市公交网建设问题
【题目描述】 有一张城市地图,图中的顶点为城市,无向边代表两个城市间的连通关系,边上的权为在这两个城市之间修建高速公路的造价,研究后发现,这个地图有一个特点,即任一对城市都是连通的。现在的问题是,要修建若干高速公路把所有城市联系起来,问如何设计可使得工程的总造价最少? 【输入】 n(城市数,1<≤n≤100) e(边数) 以下e行,每行3...原创 2020-04-27 10:23:16 · 990 阅读 · 0 评论 -
1350:最短网络(agrinet) (Kruskal)
【题目描述】 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场。当然,他需要你的帮助。约翰已经给他的农场安排了一条高速的网络线路,他想把这条线路共享给其他农场。为了用最小的消费,他想铺设最短的光纤去连接所有的农场。你将得到一份各农场之间连接费用的列表,你必须找出能连接所有农场并所用光纤最短的方案。每两个农场间的距离不会超过100000。 ...原创 2020-04-27 07:56:03 · 543 阅读 · 0 评论 -
1349:最优布线问题
【题目描述】 学校有n台计算机,为了方便数据传输,现要将它们用数据线连接起来。两台计算机被连接是指它们有数据线连接。由于计算机所处的位置不同,因此不同的两台计算机的连接费用往往是不同的。 当然,如果将任意两台计算机都用数据线连接,费用将是相当庞大的。为了节省费用,我们采用数据的间接传输手段,即一台计算机可以间接的通过若干台计算机(作为中转)来实现与另一台计算机的连接。 ...原创 2020-04-27 07:36:00 · 692 阅读 · 0 评论