随笔分类 -  最小生成树

摘要:求出最大生成树之后求LCA即可。 #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <stdio.h> #include <iomanip> #include <algorithm 阅读全文
posted @ 2018-09-09 21:55 LMissher 阅读(163) 评论(0) 推荐(0)
摘要:题目:最小生成树裸题。 注意getchar的使用。 代码: #include<cstdio>#include<cstring>#include<algorithm>using namespace std;int per[110];struct node{ char a,b; int w;}s[100 阅读全文
posted @ 2017-09-12 14:55 LMissher 阅读(116) 评论(0) 推荐(0)
摘要:题意:有n个点m条边,求用边把所有点连接起来的最小权值。 题解:当m小于n-1时是不可能的,当有自环时也不可能,排除掉这两个情况然后用Kruskal。 代码: #include <cstdio>#include <algorithm>using namespace std;int n,m,f[110 阅读全文
posted @ 2017-08-22 11:11 LMissher 阅读(130) 评论(0) 推荐(0)
摘要:题意:有n个村子与很多路,有些路已经修好了,求最小路程把所有村子连起来。 题解:用Kruskal算法,提前把已经修好的路合并。 代码: #include <cstdio>#include <algorithm>using namespace std;int n,q,Map[110][110],f[1 阅读全文
posted @ 2017-08-22 10:33 LMissher 阅读(119) 评论(0) 推荐(0)
摘要:题目:给一个矩阵告诉每条边的权,求最小生成树。 题解:建树之后直接用kruskal。 代码: #include <algorithm>#include <iostream>using namespace std;struct node{//每条边的两顶点以及距离 int from; int to; 阅读全文
posted @ 2017-08-21 10:41 LMissher 阅读(187) 评论(0) 推荐(0)
摘要:题目:给n个点,m条加权边。用最大距离连接所有点。 题解:裸的最大生成树。我用的kruskal。 代码: #include <iostream>#include <algorithm>using namespace std;struct node{//每条边的两顶点以及距离 int from; in 阅读全文
posted @ 2017-08-21 10:36 LMissher 阅读(144) 评论(0) 推荐(0)