题目链接:http://openoj.awaysoft.com:8080/judge/contest/view.action?cid=384#problem/J

 

Agri-Net
#include <stdio.h>
#include <string.h>
int dis[110][110];
int vist[110];
int main()
{
    int i,j,t,n;
    while (~scanf("%d",&n))
    {
        __int64 s=0;
        for (i=1;i<=n;i++)
            for (j=1;j<=n;j++)
                scanf("%d",&dis[i][j]);
        memset(vist,0,sizeof(vist));
        vist[1]=1;
        t=n-1;
        while (t--)
        {
            int m=100010;
            int pos;
            for (i=2;i<=n;i++)
                if (!vist[i] && dis[1][i]<m)
                {
                    pos=i;
                    m=dis[1][i];
                }
            vist[pos]=1;
            s+=m;
            for (i=2;i<=n;i++)
                if (!vist[i] && dis[pos][i]<dis[1][i])
                    dis[1][i]=dis[pos][i];
        }
        printf("%I64d\n",s);
    }
    return 0;

 

posted on 2013-04-16 19:51  Modiz  阅读(128)  评论(0编辑  收藏  举报