zoj 3080 ChiBi

Description

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, 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

40 1 2 -11 0 4 -12 4 0 -1-1 -1 -1 01 2 4 8

Sample Output

8

 

题目分析:

让你去烧曹操的船。要求在人数最少的情况下所用的最短时间。烧船的方式有两种,一是自己走过去用火点,二是借助风。已知自己到达各船的所需时间和火蔓延的速度。    因为不是所有船连在一起,所以船可以分为几个联通块(使用并查集)。又 要求人数最少。所以的话,每个联通块派一个人。最后统计每个联通块所需的最大时间。

AC代码:

#include
   
   
    
    
#include
    
    
     
     
#include
     
     
      
      
#include
      
      
       
       
#include
       
       
         #include 
        
          #define INF 0x3f3f3f3f using namespace std; int visited[1010],edge[1010][1010]; int pre[1010],root[1010],dis[1010],mark[1010]; vector 
         
           vec[1010]; int n; int fun(int x) { int t=x; while(root[x]!=x) x=root[x]; while(root[t]!=x) { t=root[t]; root[t]=x; } return x; } void mer(int a,int b) { int ra=fun(a); int rb=fun(b); if(ra==rb) return; root[ra]=rb; } int spfa(int r,int s,int k) { queue 
          
            que; int i; memset(dis,0x3f,sizeof(dis)); memset(mark,0,sizeof(mark)); dis[s]=0; mark[s]=1; que.push(s); while(!que.empty()) { int u=que.front(); que.pop(); mark[u]=0; for(i=0;i 
           
             dis[y]+edge[y][x]) { dis[x]=dis[y]+edge[y][x]; if(!mark[x]) { mark[x]=1; que.push(x); } } } } int ma=0; for(i=0;i 
            
              ma) { ma=dis[vec[r][i]]; } return ma+pre[s]; } int solve(int r,int k) { int i,m1=INF; for(i=0;i 
              
             
            
           
          
         
       
      
      
     
     
    
    
   
   

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值