ZOJ 3080 Chibi(Floyd)

赤壁

传送门
题目描述

watashi’s mm is so pretty as well as smart. Recently, she has watched the movie Chibi. So she knows more about the War of ChiBi. In the war, Cao Cao had 800,000 soldiers, much more than his opponents’. But he was defeated. One of the mistakes he made was that he connected some of his boats together, and these boats were burned by the clever opponents.
Then an interesting problem occurs to watashi’s mm. She wants to use this problem to check whether watashi is as smart as her. However, watashi has no idea about the problem. So he turns to you for help.
You know whether two boats are directly connected and the distance between them. And Fire’s speed to spread between boats is 1m/s. You also know the time your soldiers need to travel from your camp to each boat. Because burning Cao Cao’s boat is a very dangerous job, you must choose the least number of soldiers, and each one can only burn one boat. How much time do you need to burn all the Cao Cao’s boats?

Input

The input contains several test cases. Each test case begins with a line contains only one integer 0 ≤ N ≤ 1000 0 \leq N \leq 1000 0N1000, which indicates the number of boats. The next N lines, each line contains N integers in range [0, 10000], the jth number in the ith line is the distance in metre between the ith boat and the jth boat, if the number is -1, then these two boats are not directly connected(d(i, j) == d(j, i) && d(i, i) == 0). Then N intergers in range [0, 10000], the ith number is the time in second your soldiers need to travel from the camp to the ith boat. What’s more Cao Cao is not that stupid, so he won’t connect more than 100 boats together.

Output

The shortest time you need to burn all the Cao Cao’s boats counting from the soldiers leave the camp in a single line.

Sample input

4
0 1 2 -1
1 0 4 -1
2 4 0 -1
-1 -1 -1 0
1 2 4 8

Sample Output

8

翻译:

有N艘船,有一些通过铁索连在一起,每条铁索都有一个长度,现在可以派遣一些士兵去点燃一些船,火会在相连的船之间传播,传播速度是 1 m / s 1m/s 1m/s.每个士兵只能点燃一艘船。现在你知道每条铁索的长度,以及从你的大本营派兵到每条船所需的时间。
由于点燃船是一件很危险的事,所以要在派遣最少数量的士兵的条件下,使得所有船被点燃的时间最早
数据范围: 1 ≤ n ≤ 1000 1\leq n \leq 1000 1n1000,数据保证每个连通快大小不超过100.


我们先把每一个连通块做一个Floyd,然后再枚举每一个连通块中的每一艘船 i i i,使得士兵划船到i的时间+这个连通块烧完的时间加起来最小,最后求每一个连通块烧完的时间的最大值就行了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值