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 ...
随机推荐
- Day9 - Python 多线程、进程
Python之路,Day9, 进程.线程.协程篇 本节内容 操作系统发展史介绍 进程.与线程区别 python GIL全局解释器锁 线程 语法 join 线程锁之Lock\Rlock\信号量 将线 ...
- mysql复习增删改查
select * from torder where status='退款申请' UPDATE torder SET `status`='退款申请' WHERE status='等待付款' and i ...
- Linq101-Element
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Element ...
- Java编程思想-泛型-简单泛型例子
基本类型无法做为类型参数 代码如下: /** * */ package test.thinkinjava.Generics; import java.util.ArrayList; import ja ...
- .Net操作XML文件
//设置配置文件物理路径 public string xmlPath = "/manage/spider/config.xml"; protected void Page_Load ...
- 【SQL Server】SQL与Excel的数据互通导入导出
转载至:http://jingyan.baidu.com/article/73c3ce28c839b7e50243d950.html
- 困扰:C#.net 连接Oracle11g 不报错但是在connection时出现 ServerVersion 引发了“System.InvalidOperationException”类型的异常
今天在使用VS2008 32位 连接 64位的Oracle11g的数据库时出现 “conn.ServerVersion”引发了“System.InvalidOperationException”类型的 ...
- 【转】 分析iOS Crash文件:符号化iOS Crash文件的3种方法
当你的应用提交到AppStore或者各个渠道之后,请问你多久会拿到crash文件?你如何分析crash文件的呢? 上传crash文件 你的应用应当有模块能够在应用程序crash的时候上传crash信息 ...
- 关于模板中的动态取值 ---反射与javascript脚本编译
在项目中经常遇到一个问题,打印word或者打印excel的时候,我们经常使用一对一的赋值或者批量替换的方式来对模板进行修改. 但是现在遇到两种场景: 1.取值是通过自定以方法进行取值的. 如:一个销售 ...
- javascript-Cookie的应用
在我平时开发网页的过程中,可能涉及到浏览器本地的存储,现在主流的浏览器存储方式有:cookie,直接读取xml,userData,H5 的LocalStorage等,Cookie存储数据有限,但对于数 ...