【裸最小生成树】 模板 poj 1258】的更多相关文章

#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #define MAX 102 void read(); using namespace std; int map[MAX][MAX],best[MAX],n; bool visit[MAX]; int main() { //freopen("in.txt","r",stdin…
poj 1251  && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E 44E 2 F 60 G 38F 0G 1 H 35H 1 I 353A 2 B 10 C 40B 1 C 200Sample Output 21630 prim算法 # include <iostream> # include <cstdio> # include <cstr…
POJ 最小生成树模板 Kruskal算法 #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> #include<ctype.h> #include<stdlib.h> #include<limits.h> #include<math.h> #include<queue> #include<st…
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 needs your help, of course.Farmer John ordered a high speed connection for his farm and is going to share his…
链接:传送门! 题意:一个裸最小生成树,采用Kruskal. /************************************************************************* > File Name: poj1258.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ > Created Time: 2017年06月19日 星期一 18时20分30秒 ************…
#include <iostream>// poj 1258 10.1.5.253 1505 using namespace std; #define N 105 // 顶点的最大个数 (多写 int a[N][N],low[N],n,ans; int min(int x,int y) { return x<y?x:y; } void prim(int u0) { int i,j,m,k; ans=0; // for (i=1;i<n;i++) low[i]=a[u0][i]; /…
POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> const int MAXN=101; const int INF=100000+10; int map[MAXN][MAXN]; int dis[MAXN]; int n; void prim() { bool vis[MAXN]={0}; for(int i=0;i<=n;i++) dis[i]…
POJ-图论-最小生成树模板 Kruskal算法 1.初始时所有结点属于孤立的集合. 2.按照边权递增顺序遍历所有的边,若遍历到的边两个顶点仍分属不同的集合(该边即为连通这两个集合的边中权值最小的那条)则确定该边为最小生成树上的一条边,并将这两个顶点分属的集合合并. 3.遍历完所有边后,原图上所有结点属于同一个集合则被选取的边和原图中所有结点构成最小生成树:否则原图不连通,最小生成树不存在. 数据结构:引入边结构,并重载小于号运算符 struct Edge { int a, b;//边的两端结点…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 45050   Accepted: 18479 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…
用的是prim算法. 我用vector数组,每次求最小的dis时,不需要遍历所有的点,只需要遍历之前加入到vector数组中的点(即dis[v]!=INF的点).但其实时间也差不多,和遍历所有的点的方法都是16ms... #include <iostream> #include <algorithm> #include <string.h> #include <stdio.h> #include <string> #include <que…