题目背景
John的农场缺水了!!!node
题目描述
Farmer John has decided to bring water to his N (1 <= N <= 300) pastures which are conveniently numbered 1..N. He may bring water to a pasture either by building a well in that pasture or connecting the pasture via a pipe to another pasture which already has water.ios
Digging a well in pasture i costs W_i (1 <= W_i <= 100,000).ide
Connecting pastures i and j with a pipe costs P_ij (1 <= P_ij <= 100,000; P_ij = P_ji; P_ii=0).ui
Determine the minimum amount Farmer John will have to pay to water all of his pastures.spa
POINTS: 400code
农民John 决定将水引入到他的n(1<=n<=300)个牧场。他准备经过挖若blog
干井,并在各块田中修筑水道来连通各块田地以供水。在第i 号田中挖一口井须要花费W_i(1<=W_i<=100,000)元。链接i 号田与j 号田须要P_ij (1 <= P_ij <= 100,000 , P_ji=P_ij)元。ip
请求出农民John 须要为连通整个牧场的每一块田地所须要的钱数。ci
输入输出格式
输入格式:
第1 行为一个整数n。string
第2 到n+1 行每行一个整数,从上到下分别为W_1 到W_n。
第n+2 到2n+1 行为一个矩阵,表示须要的经费(P_ij)。
输出格式:
只有一行,为一个整数,表示所须要的钱数。
输入输出样例
说明
John等着用水,你只有1s时间!!!