zoukankan      html  css  js  c++  java
  • B

    有一些地方需要铺盖电缆,这些地方两点间的路可能不止一条,需要求出来至少需要多少电缆才能让所有的点都连接起来,当然,间接连接也算。

    /////////////////////////////////////////////////////////////////////////
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<queue>
    #include<vector>
    using namespace std;

    #define maxn 105

    struct node
    {
        int u, v, len;
        friend bool operator < (node a, node b)
        {
            return a.len > b.len;
        }
    };
    int f[maxn];

    int Find(int x)
    {
        if(f[x] != x)
            f[x] = Find(f[x]);
        return f[x];
    }

    int main()
    {
        int N, M;

        while(scanf("%d", &N) != EOF && N)
        {
            int i, ans=0;
            priority_queue<node>Q;
            node s;

            for(i=0; i<=N; i++)
                f[i] = i;
            scanf("%d", &M);

            while(M--)
            {
                scanf("%d%d%d", &s.u, &s.v, &s.len);
                Q.push(s);
            }

            while(Q.size())
            {
                s = Q.top();Q.pop();

                int u = Find(s.u), v = Find(s.v);

                if(u != v)
                {
                    f[u] = v;
                    ans += s.len;
                }
            }

            printf("%d ", ans);
        }

        return 0;
    }
  • 相关阅读:
    html调用hadoop WebHDFS REST API
    推荐相关
    Resources of Studying Hadoop
    远程调试Hadoop(转)
    MYSQL复制的几种模式
    Hadoop实战第四章读书笔记
    FMS3系列(七):FMS案例开发视频聊天室
    Flex与.NET互操作系列文章
    使用FluorineFx Silverlight库实现Silverlight远程过程调用(RPC)
    修改 MySQL帐号密码,增加新用户
  • 原文地址:https://www.cnblogs.com/liuxin13/p/4674370.html
Copyright © 2011-2022 走看看