博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ2421 Constructing Roads
阅读量:7099 次
发布时间:2019-06-28

本文共 1992 字,大约阅读时间需要 6 分钟。

 

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 23071   Accepted: 9894

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, or there exists a village C such that there is a road between A and C, and C and B are connected. 
We know that there are already some roads between some villages and your job is the build some roads such that all the villages are connect and the length of all the roads built is minimum.

Input

The first line is an integer N (3 <= N <= 100), which is the number of villages. Then come N lines, the i-th of which contains N integers, and the j-th of these N integers is the distance (the distance should be an integer within [1, 1000]) between village i and village j. 
Then there is an integer Q (0 <= Q <= N * (N + 1) / 2). Then come Q lines, each line contains two integers a and b (1 <= a < b <= N), which means the road between village a and village b has been built.

Output

You should output a line contains an integer, which is the length of all the roads to be built such that all the villages are connected, and this value is minimum.

Sample Input

30 990 692990 0 179692 179 011 2

Sample Output

179

Source

,kicc
 
给出一个邻接矩阵,再给出Q条已经连好的边,求最小生成树中最大边的距离。
裸最小生成树。
 
1 /*by SilverN*/ 2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 using namespace std; 9 const int mxn=3210;10 int read(){11 int x=0,f=1;char ch=getchar();12 while(ch<'0' || ch>'9'){ if(ch=='-')f=-1;ch=getchar();}13 while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}14 return x*f;15 }16 struct edge{17 int x,y;18 int d;19 }e[mxn*100];20 int cmp(const edge a,const edge b){21 return a.d

 

转载于:https://www.cnblogs.com/SilverNebula/p/6017384.html

你可能感兴趣的文章
简单PHP留言板之三 —— 头部文件以 及单 独设置PHP文件编码
查看>>
Android中Context
查看>>
WordPress超级基本教程(转)
查看>>
Python基础 3----文件和网络
查看>>
模块的耦合和内聚
查看>>
对话框
查看>>
迁移SQL SERVER 数据库实例
查看>>
HttpClient工具类v1.7
查看>>
Sqlite中使用rowid来表示行号,用于分页。
查看>>
HDU 4916 树形dp
查看>>
远程数据库迁移数据
查看>>
一些有用的java 框架
查看>>
访问不了firefox附加组件页面怎么办
查看>>
Docker image 镜像介绍
查看>>
Java线程池
查看>>
ArrayList,LinkedList,Vector,Stack之间的区别
查看>>
Freemarker常用技巧(二)
查看>>
2.C#中通过委托Func消除重复代码
查看>>
[转] 基于PHP Stream Wrapper开发有趣应用场景
查看>>
JS获取屏幕大小
查看>>