http://acm.hdu.edu.cn/showproblem.php?pid=1301

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 500
using namespace std;
const int inf=<<; int g[maxn][maxn];
int dis[maxn];
bool vis[maxn];
int n,x,mm,sum;
char ch,ch1; void prim()
{
memset(vis,false,sizeof(vis));
for(int i=; i<n; i++) dis[i]=g[][i];
dis[]=;
vis[]=true;
for(int i=; i<n; i++)
{
int m=inf,x;
for(int y=; y<n; y++) if(!vis[y]&&dis[y]<m) m=dis[x=y];
vis[x]=true;
sum+=m;
for(int y=; y<n; y++) if(!vis[y]&&dis[y]>g[x][y]) dis[y]=g[x][y];
}
} int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
getchar();
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
if(i==j) g[i][j]=;
else g[i][j]=inf;
}
}
for(int i=; i<=n-; i++)
{
scanf("%c %d%*c",&ch,&x);
for(int j=; j<x; j++)
{
scanf("%c %d%*c",&ch1,&mm);
g[ch-'A'][ch1-'A']=g[ch1-'A'][ch-'A']=mm;
}
}
sum=;
prim();
printf("%d\n",sum);
}
return ;
}

hdu 1301 Jungle Roads的更多相关文章

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

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

  2. hdu 1301 Jungle Roads 最小生成树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrish ...

  3. Hdu 1301 Jungle Roads (最小生成树)

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1301 很明显,这是一道“赤裸裸”的最小生成树的问题: 我这里采用了Kruskal算法,当然用Prim算法也 ...

  4. hdu 1301 Jungle Roads krusckal,最小生成树,并查集

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

  5. POJ 1251 & HDU 1301 Jungle Roads

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

  6. HDU 1301 Jungle Roads (最小生成树,基础题,模版解释)——同 poj 1251 Jungle Roads

    双向边,基础题,最小生成树   题目 同题目     #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<stri ...

  7. POJ 1251 + HDU 1301 Jungle Roads 【最小生成树】

    题解 这是一道裸的最小生成树题,拿来练手,题目就不放了 个人理解  Prim有些类似最短路和贪心,不断找距当前点最小距离的点 Kruskal类似于并查集,不断找最小的边,如果不是一棵树的节点就合并为一 ...

  8. 最小生成树 || HDU 1301 Jungle Roads

    裸的最小生成树 输入很蓝瘦 **并查集 int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } 找到x在并查集里的根结点,如果 ...

  9. HDOJ 1301 Jungle Roads

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 //HDOJ1301 #include<iostream>#include<c ...

随机推荐

  1. BZOJ3297: [USACO2011 Open]forgot

    3297: [USACO2011 Open]forgot Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 54  Solved: 38[Submit][ ...

  2. 【转】android:DDMS查看Threads--不错

    原文网址:http://www.cnblogs.com/mybkn/archive/2012/05/27/2520335.html 有时候程序运行出现死锁或者信号量卡死是很纠结的问题,单看代码很难分析 ...

  3. cf509E Pretty Song

    E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. java与数据结构(4)---java实现双向循环链表

    线性表之链式存储结构双向循环链表 双向循环链表:每个结点包含了数据.直接前驱地址指针和直接后驱地址指针,头结点的直接前驱指向尾结点,尾结点的直接后驱指向头结点,头尾相连构成一个可正可反的圆环.可以形象 ...

  5. Java继承与清理

    [程序实例] import java.util.*; class Characteristic { private String s; Characteristic(String s) { this. ...

  6. Chrome真机调试步骤

    确保手机端打开USB调试选项 手机安装chrome 手机访问网页(或者打开APP,或者使用夜深模拟器打开APP或者网页) PC chrome打开chrome://inspect/#devices 点击 ...

  7. jquery中的属性和css

    jQuery中的属性用于获取或设置元素的属性 1.attr(),获取或设置所有相匹配的元素的属性值:removeAttr("attr"),移除所有相匹配的元素的属性 //html ...

  8. javascript中的变量作用域

    在网上看了一道js面试题 <script type="text/javascript"> var tt = 'aa'; function test() { alert( ...

  9. 将apk文件添加到Android模拟器(AVD)中运行

    apk不同exe和jar文件,apk需要在安卓系统中运行,单有一个apk文件还是没用,不能直接拖进AVD中(当然可以直接放到安卓系统的手机中) 由于我们的eclipse大都是已经安装好,解压直接使用的 ...

  10. $_SERVER变量 以及 PHP 使用 $_SERVER['PHP_SELF'] 获取当前页面地址及其安全性问题

    PHP $_SERVER['PHP_SELF'] $_SERVER['PHP_SELF'] 表示当前 php 文件相对于网站根目录的位置地址,与 document root 相关. 假设我们有如下网址 ...