想必看这道题的时候直接看数据还有那个图就能明白什么意思吧,说的已经很清楚了,每个点都有一些相连的点和权值,求出来如果连接所有点,最小的权值是多少,赤裸裸的最小生成树。。。
************************************************************************************
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std; #define maxn 30 struct node
{
    int v, len;
    node(int v, int len):v(v),len(len){}
    friend bool operator < (node a, node b){
        return a.len > b.len;
    }
};
vector<node> G[maxn]; int prim(int s)
{
    int i, ans=, use[maxn]={}, M;
    priority_queue<node> Q;
    use[s] = ;     for(i=, M=G[s].size(); i<M; i++)
        Q.push(G[s][i]);     while(Q.size())
    {
        node q = Q.top();Q.pop();         if(use[q.v] == )
        {
            for(i=, M=G[q.v].size(); i<M; i++)
                Q.push(G[q.v][i]);
            use[q.v] = , ans += q.len;
        }
    }     for(i=; i<maxn; i++)
        G[i].clear();     return ans;
} int main()
{
    int N;     while(scanf("%d", &N) != EOF && N)
    {
        int i, u, v, len, M;
        char s[];         for(i=; i<N; i++)
        {
            scanf("%s%d", s, &M);
            u = s[] - 'A';
            while(M--)
            {
                scanf("%s%d", s, &len);
                v = s[] - 'A';
                G[u].push_back(node(v, len));
                G[v].push_back(node(u, len));
            }
        }         int ans = prim(u);         printf("%d\n", ans);
    }     return ;
}

A - Jungle Roads - poj 1251(简单)的更多相关文章

  1. (最小生成树) Jungle Roads -- POJ -- 1251

    链接: http://poj.org/problem?id=1251 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2177 ...

  2. Jungle Roads POJ - 1251 模板题

    #include<iostream> #include<cstring> #include<algorithm> using namespace std; cons ...

  3. poj 1251 Jungle Roads (最小生成树)

    poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...

  4. POJ 1251 Jungle Roads (prim)

    D - Jungle Roads Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Su ...

  5. POJ 1251 Jungle Roads - C语言 - Kruskal算法

    Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid ...

  6. POJ 1251 && HDU 1301 Jungle Roads (最小生成树)

    Jungle Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/A http://acm.hust.edu.cn/vju ...

  7. POJ 1251 Jungle Roads(最小生成树)

    题意  有n个村子  输入n  然后n-1行先输入村子的序号和与该村子相连的村子数t  后面依次输入t组s和tt s为村子序号 tt为与当前村子的距离  求链接全部村子的最短路径 还是裸的最小生成树咯 ...

  8. Jungle Roads(kruskar)

    Jungle Roads 题目链接;http://poj.org/problem?id=1251 Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  9. HDU1301 Jungle Roads

    Jungle Roads The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign ai ...

随机推荐

  1. service redis does not support chkconfig的解决办法

    原文链接: http://my.oschina.net/maczhao/blog/322931 问题解决办法如下: 必须把下面两行注释放在/etc/init.d/redis文件靠前的注释中: # ch ...

  2. bzoj 1034 (田忌赛马++)

    /* 这类题的最优策略: 自己最好的干掉对方最好的 或者 自己最差的干掉对方最差的 不能的话 用自己最差的 对阵对方最好的 这样是最优的 实现嘛 搞两个队列跑一跑 */ #include<ios ...

  3. 注册表修改IP地址和DNS等信息

    ---------------------win8系统 1. 2. 3. --------------------------------------------------------------- ...

  4. Webview的使用和注意事项

    1.webView是一个展示web网页的控件,继承 AbsoluteLayout 2.webview的俩个回调应用层: 1)webViewClient 这个对象的创建 WebViewClient my ...

  5. 运行phpize时出现:Cannot find autoconf. Please check your autoconf installation

    运行/usr/local/webserver/php/bin/phpize时出现:Configuring for:PHP Api Version: 20041225Zend Module Api No ...

  6. Swift - 10 - assert(断言)

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  7. 卸载mysql时,如何卸载干净!

    相信很多朋友在使用mysql的过程中都会遇到这样的问题,安装过程出错,或者想要换个版本,或者不想使用了,这个时候我们都需要完全卸载mysql呢?下面,就来谈一谈我的经验. 1.控制面板——>所有 ...

  8. eclipse中如何导入jar包

    如图,首先右键点击项目,选择最下面的properties, 然后进去之后点击java build path,右边会出来4个选项卡,选择libraries, 这时候最右边会有多个选项,第一个add ja ...

  9. Entity Framework中实现指定字段更新

    foreach (var entity in databasePatents) { var patentTmp = sourcePClist.FirstOrDefault(p => p.Oid ...

  10. core文件生成总结

    1.确定系统支持生成core dump文件 ulimit -c    如果返回0, 可以ulimit -c unlimited 设定 2.kill 加上信号量, kill 信号如下 信号 信号值 功能 ...