hdu 1301 Jungle Roads
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的更多相关文章
- POJ 1251 && HDU 1301 Jungle Roads (最小生成树)
Jungle Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/A http://acm.hust.edu.cn/vju ...
- hdu 1301 Jungle Roads 最小生成树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrish ...
- Hdu 1301 Jungle Roads (最小生成树)
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1301 很明显,这是一道“赤裸裸”的最小生成树的问题: 我这里采用了Kruskal算法,当然用Prim算法也 ...
- 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 ...
- POJ 1251 & HDU 1301 Jungle Roads
题目: Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign ...
- HDU 1301 Jungle Roads (最小生成树,基础题,模版解释)——同 poj 1251 Jungle Roads
双向边,基础题,最小生成树 题目 同题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<stri ...
- POJ 1251 + HDU 1301 Jungle Roads 【最小生成树】
题解 这是一道裸的最小生成树题,拿来练手,题目就不放了 个人理解 Prim有些类似最短路和贪心,不断找距当前点最小距离的点 Kruskal类似于并查集,不断找最小的边,如果不是一棵树的节点就合并为一 ...
- 最小生成树 || HDU 1301 Jungle Roads
裸的最小生成树 输入很蓝瘦 **并查集 int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } 找到x在并查集里的根结点,如果 ...
- HDOJ 1301 Jungle Roads
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 //HDOJ1301 #include<iostream>#include<c ...
随机推荐
- Storm drpc学习
示例代码: package com.lky.test; import org.apache.commons.logging.Log; import org.apache.commons.logging ...
- java中的“包”与C#中的“命名空间
原文地址:http://www.cnblogs.com/lidabo/archive/2012/12/15/2819865.html Package vs. Namespace 我们知道,重用性(re ...
- Python 2 到 Python 3的变化
Python 2.x到Python 3.x变化还是挺大的,具体的变化,参考官方文档: https://docs.python.org/3.0/whatsnew/3.0.html
- 安卓学习之路 -- JAVA多线程下载
代码没有优化,暂时先实现结果 package download; import java.io.File; import java.io.InputStream; import java.io.Ran ...
- ORCL_INSTALL_WIN10
0.相关问题 INS-13001环境不满足最低要求: Win10下安装Oracle11g 不满足配置解决方法如下: 原因:Oracle 在发布 11g时,Winodws 10还没有发布.所以Oracl ...
- Thinking In Web [原创作品]
(转载请注明:http://zhutty.cnblogs.com, 交流请加群:164858883) 可能在大部分人来讲,前端就是可见的页面数据呈现正确就行.然而这样是不正确的,页面呈现是一部分,更多 ...
- oracle递归函数
oracle start with connect by 使用方法 oracle中 connect by prior 递归算法 Oracle中start with...connect by prio ...
- Baidu与Google地图API初探
前天周六,有个好友过来玩,他说想在他的站点中加入地图导航模块,但不知道选择哪个第三方Map API 在网上查了下Baidu.Google.QQ和MapBar等4种Map API(都是採用JS开放API ...
- iscc2016 mobile1-TurtleShell.apk解题过程
拿到程序先运行,简单的验证输入的flag正确与否.jeb加载apk文件 实在库文件里面验证,所以ida加载之,so文件是加密的,所以看不到关键验证函数,百度搜了下libhackme.so,出来这篇文章 ...
- linux内存机制
~# free -m total used free shared buffers cachedMem: 16086 8579 7507 0 152 800 ...