題目背景
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時間!!!