Graph
Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 355Accepted Submission(s): 195
Problem Description
Everyone knows how to calculate the shortest path in a directed graph. In fact, the opposite problem is also easy. Given the length of shortest path between each pair of vertexes, can you find the original graph?
Input
The first line is the test case number T (T ≤ 100).
First line of each case is an integer N (1 ≤ N ≤ 100), the number of vertexes.
Following N lines each contains N integers. All these integers are less than 1000000.
The jth integer of ith line is the shortest path from vertex i to j.
The ith element of ith line is always 0. Other elements are all positive.
Output
For each case, you should output “Case k: ” first, where k indicates the case number and counts from one. Then one integer, the minimum possible edge number in original graph. Output “impossible” if such graph doesn't exist.
Sample Input
3
3
0 1 1
1 0 1
1 1 0
3
0 1 3
4 0 2
7 3 0
3
0 1 4
1 0 2
4 2 0
Sample Output
Case 1: 6
Case 2: 4
Case 3: impossible
Source
判断这个图是否合理很简单,就是利用floyd算法在做一次松弛操作。如果发现还有边可以进行松弛的话就输出impossible
然后接下来统计最小边就是去找dis[i][j]能不能表示为dis[i][k]+dis[k][j]的形式
所以说这个题实际上是考察了floyd算法的理解
我的代码:
分享到:
相关推荐
收集的部分HDOJ杭电ACM题的代码 大牛勿下 全是基础供初级acmer使用
ACM ICPC HDOJ1000
自己积累的部分杭电oj的(hdu)解题代码。。大家有空来看看。 基本上是自己写的哈。有错误之处请指教、
杭电acm解题报告 详细解析2000-2099 适合acm初学者
HDOJ题目分类HDOJ题目分类HDOJ题目分类
HDOJ,2011阿里巴巴程序设计公开赛的标程 题目位置:http://acm.hdu.edu.cn/vip/2011alibaba/index.php
杭电 OJ Java版的,考虑到大多数都是c++版的,或许Java版的会对你有所帮助。
ACM ICPC HDOJ1002
ACM ICPC HDOJ1001
hdoj1001标程
hdoj上的资源,代码有注释,很不错的哦
杭州电子科技大学hdoj1002,大整数相加问题
codj,hdoj的源码(50-60题)
hdoj1004,解题代码,答案代码,欢迎下载
杭电oj4405,一道简单的概率dp题目
ACM ICPC HDOJ1008
ACM ICPC HDOJ1003
杭州电子科大HDOJ
hdoj解题代码,题目为1000-1050
c语言 最短路 是hdoj上的一个最短路问题,写的很牛