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…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14172    Accepted Submission(s): 5402 Problem Description There are N villa…
Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13995    Accepted Submission(s): 5324 Problem Description There are N villages, which are numbered from 1 to N, and you should…
Constructing Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 274 Accepted Submission(s): 172   Problem Description There are N villages, which are numbered from 1 to N, and you should build…
嘎唔!~又一次POJ过了HDU错了...不禁让我想起前两天的的Is it a tree?   orz..这次竟然错在HDU一定要是多组数据输入输出!(无力吐槽TT)..题目很简单,炒鸡水! 题意: 告诉你每个村庄之间的距离,和几组已经联通的村庄,求使所有村庄联通所要建的道路的最短距离. 很简单,用最小生成树的Prim算法,相当于邻接矩阵已知,把已联通的村庄之间的距离改为零即可. 附上AC代码: #include <stdio.h> #include <string.h> #incl…
题意: 有N个点,有些点已经连接了,然后求出所有点的连接的最短路径是多少. 思路: 最小生成树的变形,有的点已经连接了,就直接把他们的权值赋为0,一样的就做最小生成树. 代码: prime: #include <cstdio> #include <iostream> using namespace std; #define maxn 100+5 #define inf 0x3f3f3f3f int maps[maxn][maxn]; bool vis[maxn]; int dis[…
Problem 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 between A and B…
题目链接: http://poj.org/problem?id=2421 想把n个村庄连接在一起:求最小生成树,不同的是已经有了m条线段链接在一起了,求剩下的: 感觉用Kruskal会简单一点 #include<stdio.h> #include<string.h> #include<map> #include<iostream> #include<algorithm> #include<math.h> #define N 110 #…
题意: 输入n,然后接下来有n-1行表示边的加边的权值情况.如A 2 B 12 I 25 表示A有两个邻点,B和I,A-B权值是12,A-I权值是25.求连接这棵树的最小权值. 思路: 一开始是在做莫队然后发现没学过最小生成树,就跑过来做模板题了... Kruskal的使用过程:先按权值大小排序,然后用并查集判断是否能加这条边 Kruskal详解博客:[贪心法求解最小生成树之Kruskal算法详细分析]---Greedy Algorithm for MST 考试周还在敲代码...我... upd…