아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Agri-Net

면접 대비

시간 제한1초메모리 제한1024 MB

요약
농장 사이의 연결 비용을 나타내는 N x N 대칭 행렬이 주어질 때, 모든 농장을 연결하는 최소 신장 트리의 총 비용을 구한다.
난이도

보통10점 중 4점

유형
최소 신장 트리, 그래프, 그리디, 행렬
정답자
아직 제출이 없습니다

문제

Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.

Farmer John ordered a high speed connection for his farm and is going to share his connectivity with the other farmers. To minimize cost, he wants to lay the minimum amount of optical fiber to connect his farm to all the other farms.

Given a list of how much fiber it takes to connect each pair of farms, you must find the minimum amount of fiber needed to connect them all together. Each farm must connected to some other farm such that a path exists from any farm to any other farm.

입력

The first line of input is the number of farms, N (3 ≤ N ≤ 100). Each line i of N subsequent lines contains N non-negative integers (each less than 32000) that represent the distance between farm i and farms 1, 2, 3, ..., N. Of course, the diagonal will be 0, since the distance from farm i to itself is not interesting for this problem.

출력

The single output contains the integer length that is the sum of the minimum length of fiber required to connect the entire set of farms.

예제1

  1. 예제 1

    입력
    4
    0 4 9 21
    4 0 8 17
    9 8 0 16
    21 17 16 0
    
    예상 출력
    28