시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 128 MB 31 15 14 56.000%

문제

선주는 자신이 운영하는 N개의 논에 물을 대려고 한다. 물을 대는 방법은 두 가지가 있는데 하나는 직접 논에 우물을 파는 것이고 다른 하나는 이미 물을 대고 있는 다른 논으로부터 물을 끌어오는 법이다.

각각의 논에 대해 우물을 파는 비용과 논들 사이에 물을 끌어오는 비용들이 주어졌을 때 최소의 비용으로 모든 논에 물을 대는 것이 문제이다.

입력

첫 줄에는 논의 수 N(1 ≤ N ≤ 300)이 주어진다. 다음 N개의 줄에는 i번째 논에 우물을 팔 때 드는 비용 Wi(1 ≤ Wi ≤ 100,000)가 순서대로 들어온다. 다음 N개의 줄에 대해서는 각 줄에 N개의 수가 들어오는데 이는 i번째 논과 j번째 논을 연결하는데 드는 비용 Pi,j(1 ≤ Pi,j ≤ 100,000, Pi,j = Pj,i, Pi,i = 0)를 의미한다.

출력

첫 줄에 모든 논에 물을 대는데 필요한 최소비용을 출력한다.

예제 입력 1

4
5
4
4
3
0 2 2 2
2 0 3 3
2 3 0 4
2 3 4 0

예제 출력 1

9
W3sicHJvYmxlbV9pZCI6IjEzNjgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJiM2NcdWIzMDBcdWFlMzAiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzEyMFx1YzhmY1x1YjI5NCBcdWM3OTBcdWMyZTBcdWM3NzQgXHVjNmI0XHVjNjAxXHVkNTU4XHViMjk0IE5cdWFjMWNcdWM3NTggXHViMTdjXHVjNWQwIFx1YmIzY1x1Yzc0NCBcdWIzMDBcdWI4MjRcdWFjZTAgXHVkNTVjXHViMmU0LiBcdWJiM2NcdWM3NDQgXHViMzAwXHViMjk0IFx1YmMyOVx1YmM5NVx1Yzc0MCBcdWI0NTAgXHVhYzAwXHVjOWMwXHVhYzAwIFx1Yzc4OFx1YjI5NFx1YjM3MCBcdWQ1NThcdWIwOThcdWIyOTQgXHVjOWMxXHV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