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 ...
随机推荐
- 使用NAT方式连网的linux服务器虚拟机搭建
从一开始我就很纠结centos服务器搭建的过程. 由于自己方向并不在运维上,但是学习开发也需要用到Linux所以就一直没认真去学. 经过自己多方面摸索与学习找到了自己的一套方法. 首先我用到的是 ce ...
- 如何学习H264协议
如何学习h.264协议 首先,我假定你已经具有如下基础: 1 了解基本的视频知识,知道什么是YCbCr/YUV: 2 知道基本的视频压缩原理: 如果这两条还不具备,那么,停一下,补一下课.这方面的相关 ...
- css.day03
css的分类(位置): css层叠样式表 1.内嵌 样式表 2.行内样式表 3. 外连 css选择器分类 基础选择器 标签 id选择器 类选择器 复合选择器 交集选择器(标签指定式) span.on ...
- 关于开发C#中的asp.net中gridview控件的使用
原文网址:http://blog.sina.com.cn/s/blog_67f1b4b201017663.html 1.GridView无代码分页排序: 效果图: 1.AllowSorting设为Tr ...
- C# Word常用操作(转)格式设置
一.word文档表格操作.分页及换行 //合并单元格table.Cell(2, 2).Merge(table.Cell(2, 3)); //单元格分离 object Rownum = 2;object ...
- this,super关键字的使用
this关键字 1.this是对象的别名,是当前类的实例引用 2.在类的成员方法内部使用,代替当前类的实例.在Java中,本质上是指针,相当于C++中的指针概念.如果方法中的成员在调用前没有操作实例名 ...
- cxf webservice异步调用
http://blog.csdn.net/changpingchen/article/details/9048347 http://www.oschina.net/question/780719_12 ...
- Swift - 11 - nil聚合运算
//: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...
- cmakelists 语法学习
1.项目最外层cmake编写:----------用于kdevelop编译器 project(filtering) cmake_minimum_required(VERSION 2.8) ————必须 ...
- js实现输入验证码
html部分: <div> <input type="text" id="input" /> <input type=" ...