
kruskal
goto_1600
我何来寂寞,哪有寂寞可言。
展开
-
最小生成树,所有连通边的最大值
我唯一想说的是:我卢本伟没有开挂 ,第二句话是个废话,让一个树连通,边的数量是定制n-1(n为点数)。#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#includ...原创 2020-04-29 17:45:33 · 403 阅读 · 0 评论 -
最小生成树(士兵招募)
Windy has a country, and he wants to build an army to protect his country. He has picked up N girls and M boys and wants to collect them to be his soldiers. To collect a soldier without any privilege,...原创 2020-04-18 11:15:23 · 454 阅读 · 0 评论 -
kruskal求最小生成树
思路:先按照每条边的权值排序,从小到大枚举每条边,如果这条边两个顶点的祖宗节点不一样,连接上这条边并且计数器加一,最后如果计数器小于顶点个数-1的话,就说明不到n个点,就不可能,否则输出答案代码如下:#include<iostream>using namespace std;const int N=100010;int p[N];int find(int x){if(x!...原创 2020-02-10 22:43:16 · 235 阅读 · 0 评论