首页
DreamJudge
院校信息
考研初试
机试真题
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
xiaofan618
2025年3月16日 18:15
最小生成树 题解:Prim--找邻接最小边,无需并查集判断回环
P1611
回复 0
|
赞 5
|
浏览 417
prim #include<stdio.h> #include<bits/stdc++.h> #include<vector> using namespace std; struct node { int x;//连接的点 long long int w;//权值 }; int xi,yi,N,M,ans=0;long long int zi; bool vis[5001]; void dfs(int x,vector<node> g[]) { vis[x]=1;//标记访问 ...
AlbertTuring
2023年6月29日 15:56
kruskal模板的简洁写法
P1611
回复 0
|
赞 9
|
浏览 1.2k
#include<iostream> #include<algorithm> using namespace std; struct edge { int a, b, w; bool operator<(const edge& e) const { return w<e.w; } }; const int M = 200010, N = 5010; int n,m; edge e[M]; int p[N]; int find(int x...
all-clear
2020年5月1日 12:54
Kruscal模板24ms
P1611
回复 1
|
赞 6
|
浏览 8.8k
Kruscal是采用贪心思想,基于加边策略的MST算法。 用并查集管理顶点之间的连通性。 操作两步走: 1.对所有边按照权重升序进行排序 2.从权重最小的边开始,遍历所有的边,只要两个顶点没有连通,则添加这条边,同时统计权重 #include<cstdio> #include<vector> #include<algorithm> using namespace std; #define N 5005 //点 #define M 200005 //边 struct Edge{ int s;//起点...
题目
最小生成树
题解数量
3
发布题解
在线答疑
热门题解
1
kruskal模板的简洁写法
2
Kruscal模板24ms
3
最小生成树 题解:Prim--找邻接最小边,无需并查集判断回环