A - Jungle Roads - poj 1251(简单)
#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(简单)的更多相关文章
- (最小生成树) Jungle Roads -- POJ -- 1251
链接: http://poj.org/problem?id=1251 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2177 ...
- Jungle Roads POJ - 1251 模板题
#include<iostream> #include<cstring> #include<algorithm> using namespace std; cons ...
- poj 1251 Jungle Roads (最小生成树)
poj 1251 Jungle Roads (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...
- POJ 1251 Jungle Roads (prim)
D - Jungle Roads Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Su ...
- POJ 1251 Jungle Roads - C语言 - Kruskal算法
Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid ...
- POJ 1251 && HDU 1301 Jungle Roads (最小生成树)
Jungle Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/A http://acm.hust.edu.cn/vju ...
- POJ 1251 Jungle Roads(最小生成树)
题意 有n个村子 输入n 然后n-1行先输入村子的序号和与该村子相连的村子数t 后面依次输入t组s和tt s为村子序号 tt为与当前村子的距离 求链接全部村子的最短路径 还是裸的最小生成树咯 ...
- Jungle Roads(kruskar)
Jungle Roads 题目链接;http://poj.org/problem?id=1251 Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- HDU1301 Jungle Roads
Jungle Roads The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign ai ...
随机推荐
- Builder 建造者模式
简介 建造者模式的概念:将一个复杂的对象的构建与它的表示分离,使得同样的构建过程可以有不同的表示. 大概的意思,就是一套的构建过程可以有不同的产品(表示)出来.这些产品(表示)都按照这一套的构建过程被 ...
- ButterKnife 注解
简介 官网:http://jakewharton.github.io/butterknife/ github:https://github.com/JakeWharton/butterknife 依赖 ...
- 从一个SVN下载的导入另一个SVN里面
如果项目是你从个一个SVN下载的,你想存入另一个SVN里面 那么问题来了 你用eclipse的team的时候会发现没有Team share 这个选项,那么就等于是没有上传的选项了 解决办法,把项目删掉 ...
- updatepanel的用法之triggers
triggers有的两种触发器asyncpostbacktrigger和postbacktrigger.asyncpostbacktrigger(异步回调触发器):局部刷新,只刷新updatepane ...
- SQL DMO のDMV
这两天对公司的一个项目进行优化,看着长长的SQL,脑袋不经有些大,一时间竟然不知道如何下手,一顿手忙脚乱后,小有成效,响应速度快了不少,同样的条件下可以做到秒级响应.闲暇时间想了想,还是得做点功课,最 ...
- centos 给鼠标右击添加 “打开终端” 菜单项
1.以root身份在终端执行如下命令 yum -y install nautilus-open-terminal 2.重启操作系统 shutdown -r now
- 第一个shell编程,输出hello world!
在计算机科学中,Shell俗称壳(用来区别于核),是指“提供使用者使用界面”的软件(命令解析器).它类似于DOS下的command和后来的cmd.exe.它接收用户命令,然后调用相应的应用程序.--- ...
- input, textarea,监听输入事件
IE使用'propertychange'事件监听,其它浏览器使用'input'事件测试了IE7-10, Chrome, FF, 输入没有问题.♥但在IE9下, 删除, 回退, Ctrl+X 没有 ...
- C++ Primer 5th 第13章 拷贝控制
当一个对象的引用或者指针离开作用域时,析构函数不会执行. 构造函数有初始化部分(初始化列表)和函数体. 析构函数有析构部分和函数,但析构函数的析构部分是隐式的.
- MyBatis学习笔记(3)—— 利用mybatis灌入假数据
由于第三方厂商未能按时提供实时数据,故需要纯手动导入一些实时数据,用于统计分析.正好最近自己学习了mybatis .因此使用mybatis 配置一个select.insert 的简单操作语句,用于灌入 ...