POJ1258 基础最小生成树】的更多相关文章

本文出自:http://blog.csdn.net/svitter 题意:给出一个数字n代表邻接矩阵的大小,随后给出邻接矩阵的值.输出最小生成树的权值. 题解: prime算法的基本解法: 1.选择一个点,然后不停的向当中增加权值最小的边,边的一端在已经生成的部分生成树中,还有一端在未生成的生成树中. 2.利用优先队列维护边,将增加的点所包括的边增加到队列中去,随后依照边的权值弹出. 简单理解方法:一个人能够拉非常多人,新被拉进来的人,把能拉的人(有边,且未被訪问)排队,找最好拉的人拉进来,循环…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 46319   Accepted: 19052 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
//克鲁斯卡尔(最小生成树) #include<cstdio> #include<iostream> #include<algorithm> using namespace std; ; int n, t; struct node { int bagin, end, len; }arr[maxn]; int fa[maxn]; void init() { ; i <= n; i++) { fa[i] = i; } } bool cmp(node a, node b…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44032   Accepted: 18001 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
#include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <string> using namespace std; int n, m; ]; struct node { int u, v; double w; }map[]; int getf(int a) { if (f[a] == a) { return a; } f[a] = ge…
#include<iostream> #include<algorithm> using namespace std; ; int n, m; ]; struct node { int x, y; int cost; }arr[maxn]; void init() { ; i <= maxn; i++) { fa[i] = i; } } int find(int x) { if (x != fa[x]) { return find(fa[x]); } else return…
#include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> using namespace std; #define MAXN 10005 int fa[MAXN]; struct node { int from, to, len; }arr[MAXN]; bool cmp(node a, node b) { return a.len < b.len; } int…
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; ; ; ; int t, n, m, ans; double total; struct node { int x, y; int cost; }pot[maxn]; int fa[maxn]; int px[maxn], py[maxn]; int cal() { int i, j, tx, ty, len, pos; p…
#include <iostream> #include <cstdio> #include <algorithm> #define N 110 #define M 5000 using namespace std; int n, m, u[M], v[M], w[M], r[M], p[N]; bool cmp(int i, int j){ return w[i]<w[j]; } int f(int x){ return p[x] == x ? x : p[x]…
//克鲁斯卡尔 #include<iostream> #include<algorithm> using namespace std; ; struct node { int begin, end, len; }cun[maxn]; int n, fa[maxn], ans, m; bool cmp(node a, node b) { return a.len<b.len; //按长度有小到大排序 } void init() { ; i <= n; i++) { fa[…