最小生成树
andyc_03
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
P2872 [USACO07DEC]Building Roads S
题目描述 Farmer John had just acquired several new farms! He wants to connect the farms with roads so that he can travel from any farm to any other farm via a sequence of roads; roads already connect some of the farms. Each of the N (1 ≤ N ≤ 1,000) farms (co原创 2020-11-16 22:47:23 · 401 阅读 · 0 评论 -
【最小生成树】P2212 [USACO14MAR]Watering the Fields S
大于等于c的建边,跑kruskal即可 #include<bits/stdc++.h> using namespace std; const int maxn=2005; int n,c,tot; int x[maxn],y[maxn],f[maxn]; struct edge { int u,v,w; }e[maxn*maxn]; bool cmp(edge aa ,edge bb) { return aa.w<bb.w; } int find(int x) { if(x.原创 2020-08-02 13:17:07 · 194 阅读 · 0 评论 -
【最小生成树】P2323 [HNOI2006]公路修建问题
贪心的考虑,由于一级公路比二级公路消耗大,还要求至少有k条一级的,那么我们就正好取k条一级的公路kruskal,剩下的n-k-1条就直接按照二级价格kruskal即可 注意多次排序的关键字,以及输出的顺序 #include<bits/stdc++.h> using namespace std; const int maxn=1e4+5; int n,k,m,f[maxn],ans; struct edge { int u,v,w1,w2,num; }e[maxn<<1].原创 2020-08-02 00:50:24 · 423 阅读 · 0 评论 -
【最小生成树】P4047 [JSOI2010]部落划分
由于要求两个部落之间的最小距离最大,可以每次先连接两个最近的节点,就和最小生成树的思路一样了 代码 #include<bits/stdc++.h> using namespace std; struct node { int u,v; double w; }a[1000000]; int n,f[10000],cnt,k,l; int x[10000],y[10000]; void add(int uu,int vv,double ww) {a[++cnt]..原创 2020-08-01 22:14:15 · 145 阅读 · 0 评论
分享