Poj(1251),Prim字符的最小生成树】的更多相关文章

题目链接:http://poj.org/problem?id=1251 字符用%s好了,方便一点. #include <stdio.h> #include <string.h> #define INF 0x3f3f3f3f ][]; ]; ]; int n; int Prim() { memset(vis,false,sizeof(vis)); ; i<=n; i++) dis[i] = INF; ; dis[] = ; ; i<=n; i++) { ; ; j<…
题意  有n个村子  输入n  然后n-1行先输入村子的序号和与该村子相连的村子数t  后面依次输入t组s和tt s为村子序号 tt为与当前村子的距离  求链接全部村子的最短路径 还是裸的最小生成树咯 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=30,M=1000; int par[N],n,m,ans; struct edge{int u…
题目: Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too exp…
#include<iostream> #include<algorithm> using namespace std; ,tot=; const int N = 1e5; ]; struct ac{ int v,u,w; }edge[N]; bool cmp(ac a,ac b){ return a.w<b.w; } inline int find(int x){ if(x!=f[x])f[x]=find(f[x]);return f[x]; } inline int joi…
poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23507   Accepted: 11012 Description The Head Elder of the tropical island of Lagrishan has a problem. A b…
D - Jungle Roads Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1251 Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extr…
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…
prim 算法求最小生成树 还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20712    Accepted Submission(s): 9213 Problem Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不…
标题: Prim和Kruskal最小生成树时 限: 2000 ms内存限制: 15000 K总时限: 3000 ms描述: 给出一个矩阵,要求以矩阵方式单步输出生成过程.要求先输出Prim生成过程,再输出Kruskal,每个矩阵输出后换行.注意,题中矩阵表示无向图输入: 结点数矩阵输出: Prim:矩阵输出 Kruskal:矩阵输出输入样例: 3 0 1 3 1 0 2 3 2 0 输出样例: 3 0 1 3 1 0 2 3 2 0Prim: 0 0 0 0 0 0 0 0 0 0 1 0 1…
Kruskal算法求最小生成树 测试数据: 5 6 0 1 5 0 2 3 1 2 4 2 4 2 2 3 1 1 4 1 输出: 2 3 1 1 4 1 2 4 2 0 2 3 思路:在保证不产生回路的情况下,选择权值小的边.是否产生回路采用并查集来实现 判断两个点是否连通:如果两个点的祖先不是同一个,说明这两个点不可联通,要标志两个点联通,只要使两个点的祖先是同一个.关于并查集的讲解可以看我转载的一篇文章. 比如初始化的时候ABC的祖先是他自己,先加入了AB这条边,这两个点的的父亲不一样,可…