
Kruskal OR Prim
Sirius_Ren
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇自己刮~~~
展开
-
NOIP2013 D1T3 货车运输 倍增LCA OR 并查集按秩合并
思路: Kruskal求最大生成树+倍增LCA// by SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 105000 int n,m,tot=0,xx,yy,zz,ans; int first[N],v[N*10],next[N*10],w[N*1原创 2016-07-13 07:54:47 · 1177 阅读 · 0 评论 -
NOIP2013 D1T3 货车运输
[NOIP2013T3]货车运输背景noip2013day1描述A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路。每一条道路对车辆都有重 量限制,简称限重。现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过车辆限重的 情况下,最多能运多重的货物。输入格式输入文件第一行有两个用一个空格隔开的整数 n, m, 表示 A 国有 n 座城市和 m 条道 路。 接下来 m原创 2016-07-15 23:47:38 · 1182 阅读 · 0 评论 -
POJ 2728 最优比率生成树
(今天才学会Prim 尴尬……)这题好久之前(四个月之前)就写过。。 当时WA了……抄得题解现在终于搞对了。// by SiriusRen #include <cmath> #include <cstdio> #include <cstring> #define N 1005 using namespace std; int n,now; double map[N][N],h[N][N],low,原创 2016-08-04 20:56:36 · 600 阅读 · 0 评论 -
POJ 2377 最大生成树
思路: 裸的最大生成树 不解释//By SiriusRen #include <cstdio> #include <algorithm> using namespace std; int n,m,ans=0,cnt=0,f[100050]; struct Node{int x,y,w;}node[20050]; int find(int x){return x==f[x]?x:f[x]=find原创 2016-08-28 16:59:58 · 703 阅读 · 0 评论 -
BZOJ 1232 Kruskal
思路: 跟昨天的考试题特别像…..就是裸的Kruskal 把边权设为连接的两个点的点权之和加上边权*2搞定//By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,m,c[10005],f[10005],minn=0x3fffffff,ans; stru原创 2016-10-27 15:58:05 · 660 阅读 · 0 评论 -
BZOJ 4144 Dijkstra+Kruskal+倍增LCA
思路: 先把所有的加油站 push进按weight排序的优先队列里 对于每个不是加油站的点 找到到它的点的最短路以及它来源的加油站 如果x和y有边 且x和y加油站的来源不一样 则它可以连边跑一边Kruskal倍增查一下 搞定了(注意图可能不连通)//By SiriusRen #include <queue> #include <cstdio> #include <cstring> #原创 2016-11-08 23:29:23 · 936 阅读 · 0 评论 -
BZOJ 3624 并查集 (Kruskal)
思路: 先把所有能加上的水泥路都加上 判断哪些是必加的鹅卵石路再重新做一遍最小生成树 加上必加的鹅卵石路 一直加鹅卵石路 判一下是不是=k 最后加上水泥路就好了//By SiriusRen #include <cstdio> using namespace std; const int N=100050; int n,m,k,f[N],top; struct Node{int u,v,原创 2017-01-30 11:27:49 · 377 阅读 · 0 评论 -
BZOJ 1196 二分+Kruskal
思路: 二分答案 判一下能不能加//By SirisuRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N=40050; int n,m,k,xx,yy,aa,bb,ans,f[N],top; struct Node{ int from,to,type,原创 2017-03-04 21:12:37 · 443 阅读 · 0 评论