想必看这道题的时候直接看数据还有那个图就能明白什么意思吧,说的已经很清楚了,每个点都有一些相连的点和权值,求出来如果连接所有点,最小的权值是多少,赤裸裸的最小生成树。。。
************************************************************************************
#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. bitbucket/github同一站点上多个git代码仓库的ssh-key配置

    由于项目开发需要,可能多个项目都放在bitbucket或者github上面,每个项目都有独立的sshkey,这就会造成push时的系统默认取~/.ssh/id_rsa的问题. 最简单的解决方法是这样: ...

  2. C#解leetcode 228. Summary Ranges Easy

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  3. 转载:C#之接口简介

    原文地址 http://www.cnblogs.com/michaelxu/archive/2007/03/29/692021.html 感谢博主分享! 什么是接口?其实,接口简单理解就是一种约定,使 ...

  4. 关于 rem 作为单位设置大小

    rem是相对长度单位.相对于根元素(即html元素)font-size计算值的倍数htm{font-size: 62.5%;}根元素(html)先设置一个font-size,一般情况下为了容易计算re ...

  5. pod install后出现的错误

    [!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use T ...

  6. 05_Smart-image通过SoftReference提高性能

    文章导读: 文件介绍了常见的图片下载开源插件smart-image, 由于移动设备硬件受限,因此Android的相关app都要考虑到性能的关系, 所以很多的第三方插件都使用到了缓存cache技术,本人 ...

  7. NOI 191钉子和小球.cpp

    #include<iostream> #include<cstdio> #include<cstring> using namespace std; ][]; in ...

  8. IOS 真机调试以及发布应用 2

    参考网站:http://my.oschina.net/u/1245365/blog/196420 已经有开发证书的直接跳过第一步 第一步:申请“开发证书” 进入苹果开发者99美元账号: 选择:Cert ...

  9. c/c++内存机制(一)(转)

    转自:http://www.cnblogs.com/ComputerG/archive/2012/02/01/2334898.html 一:C语言中的内存机制 在C语言中,内存主要分为如下5个存储区: ...

  10. nodejs读取本地txt文件并输出到浏览器

    var fs = require('fs'); var chrome=""; //同步执行 function tongbu(){ var data =fs.readFileSync ...