# Graph

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

• 写回答

#### 2条回答默认 最新

• threenewbee 2017-02-20 15:26
关注
本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

#### 悬赏问题

• ¥15 求指导储层饱和度及含水率测井解释
• ¥200 建三维地震工区写入sgy到指定目录
• ¥30 靶向捕获测序探针设计自学
• ¥15 写代码写代码单片机代码写代码写数字按键代码
• ¥15 django按照距离进行排序
• ¥15 (标签-微信|关键词-微信公众号)
• ¥15 matlab中mjs用不了
• ¥15 Ios抖音直播的时候如何添加自定义图片在直播间！
• ¥60 riscv-pulpino总线上挂载axi从机
• ¥15 ssh登录页面的问题