链接: http://poj.org/problem?id=2421 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21130   Accepted: 8924 Description There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can…
思路:首先使用二维数组dis[][]处理输入, 对于已经修好的路,将其对应的dis[i][j]置为零即可.最后再将    所有的dis[][]保存到边结构体中,使用Kruskal算法求得最小生成树. #include<iostream> #include<vector> #include<string> #include<cmath> #include<set> #include<algorithm> #include<cstd…
#include<iostream> #include<cstring> #include<algorithm> using namespace std; ; int p[N]; struct edge{ int a; int b; int w; }e[N*N]; int map[N][N],flag[N][N],num,n; bool cmp(edge a,edge b) { return a.w<b.w; } int find(int x) { if(p[x]…
题目链接:https://vjudge.net/problem/POJ-2421 思路:一些村庄,建一些路,使得所有村庄能相连,而且使得所有路长度之和最短. 题目说了,有些村庄之间已经建了路,说明有些路我们不需要建,那么在预处理的时候 把那些已经建过边的两个村庄的距离赋值为0,那么在跑最小生成树板子的时候就完成了 一些路已经建立的情况. #include <stdio.h> #include <iostream> #include <queue> using names…
链接: http://poj.org/problem?id=1251 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21776   Accepted: 10086 Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra road…
Constructing Roads Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2421 Appoint description:  System Crawler  (2015-05-27) Description There are N villages, which are numbered from 1 to N, and y…
Constructing Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/D Description There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two villa…
Constructing Roads Description There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if there is a road betw…
Constructing Roads Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19884   Accepted: 8315 Description There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each…
最小生成树模板(嗯……在kuangbin模板里面抄的……) 最小生成树(prim) /** Prim求MST * 耗费矩阵cost[][],标号从0开始,0~n-1 * 返回最小生成树的权值,返回-1表示原图不连通 */ const int INF = 0x3f3f3f3f; const int MAXN = 110; bool vis[MAXN]; int lowc[MAXN]; int map[MAXN][MAXN]; int Prim(int cost[][MAXN], int n) {…