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 ...
随机推荐
- Swift - 23 - 选择结构
//: Playground - noun: a place where people can play import UIKit var rating = "A" // if - ...
- Linux shell日常命令和技巧
转自:http://www.vaikan.com/linux-shell-tips-and-tricks/ 原文:http://www.techbar.me/linux-shell-tips/ 使用L ...
- 【USACO 2.2.2】集合
[题目描述] 对于从1到N (1 <= N <= 39) 的连续整数集合,能划分成两个子集合,且保证每个集合的数字和是相等的.举个例子,如果N=3,对于{1,2,3}能划分成两个子集合,每 ...
- oracle创建表空间、用户、用户授权、删除表空间、删除用户
--创建临时表空间 create temporary tablespace test_temp --test_temp表空间名称 tempfile 'E:\oracle\product\10.2.0\ ...
- sublime3 插件pylinter的安装
1.首先sublime需要安装package control,之后安装pylinter插件,并进行简单的属性配置(网上教程很多,略) 2.之后是pylint_path的配置,我参照网上的配置失败,su ...
- 离线安装maven,重新打开eclipse报错处理方法
报错截图如下 1.eclipse 添加 jre Window -> Preferences -> Java -> Installed JREs If you can’t find a ...
- python学习第二课要点记录
字典使用时,使用for k,v in items():要将字典转换为元组,因此效率较低,如果数据量较大,就不建议使用这样的形式获取key和value的值,而要使用 for item in dict: ...
- centos+nginx+uwsgi+virtualenv+flask 多站点环境搭建
环境: centos x64 6.6 nginx 1.6.2 python 2.7.9 uwsgi 2.0.9 virtualenv 12.0.5 flask 0.10.1 正文: 1.安装nginx ...
- 【学习笔记】【oc】指针
1.取一个变量的值,可通过直接与间接的方式 直接:访问变量 间接:通过变量的内存地址来获取变量的值. 存放内存地址的变量就是指针变量. 2.定义指针变量的语法:类型* 变量名 &:取地址运算符 ...
- Mifare S50与Mifare S70
转自http://blog.sina.com.cn/s/blog_9ed067ad0100zyjx.html Mifare S50和Mifare S70又常被称为Mifare Standard.Mif ...