编程介的小学生 2017-02-26 05:01 采纳率: 20.5%
浏览 681
已采纳

Christopher's Key Ring

As you've known in "Christopher's Christmas Letter" problem, Christopher has been out of danger. But soon he found that he lost a key ring in the hospital, which was a precious Christmas gift from his lover. Certainly Christopher does NOT want to lose it, lose the past beatific state of mind. Don't you have the heart to help him?

Naturally, he won't ask you to find it physically, coz he could hire a child labor for physical help. But involved problem he met is that he should give exact amount of money to the child labor, neither more nor less than the money needed. (I'm sorry to tell you that he has spent too much money in hospital, and must be economical now). For a single unit length's examination, Christopher should pay 1 dollar.

The ichnograph of hospital is a TREE in graph theory, i.e. there's exactly one path between every pair of nodes. Sickrooms in the hospital are all leaf nodes. Corridors connecting them might intersect at some guarding rooms (they are considered as particles). How to count the total length of corridors? Christopher ALWAYS counts the same unit of length again and again, so he calls you for help.

Sadly, the only information that could be gained from the principal of hospital is the distance between every pair of sickrooms.

Input

The first line of input contains a number X which denotes the number of test cases. For each test case:

Line 1: n (2 <= n <= 777) Number of the rooms in the hospital

Line 2~n+1: The number in (i+1)th row and jth column denotes the distance between sickroom i and sick room j (not more than . We ensure the number in (i+1)th row and ith column is always ZERO, and the number in (i+1)th row and jth column is always SAME as the number in (j+1)th row and ith column.

There're NO breakline between two continuous test cases.

Output

Exact X lines, each one contains the number money (in dollars) should be paid. We guarantee that the answer won't be larger than 10^9.

Sample Input

2
3
0 6 5
6 0 7
5 7 0
3
0 6 5
6 0 7
5 7 0

Sample Output

9
9

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-03 21:15
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭