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 ...
随机推荐
- Android系统移植与驱动开发——第六章——使用实例来理解Linux驱动开发及心得
Linux驱动的工作方式就是交互.例如向Linux打印机驱动发送一个打印命令,可以直接使用C语言函数open打开设备文件,在使用C语言函数ioctl向该驱动的设备文件发送打印命令.编写Linux驱动最 ...
- Lambda表达式 简介 语法 示例
Lambda 表达式也称为闭包,是匿名类的简短形式.Lambda 表达式简化了[单一抽象方法声明接口]的使用,因此 lambda 表达式也称为功能接口. 在 Java SE 7 中,单一方法接口可使用 ...
- ST表poj3264
/* ST表多次查询区间最小值 设 g[j][i] 表示从第 i 个数到第 i + 2 ^ j - 1 个数之间的最小值 类似DP的说 ans[i][j]=min (ans[i][mid],ans ...
- 将datagrid中数据导出到excel中 -------<<工作日志2014-6-6>>
前台datagrid数据绑定 #region 导出到excel中 /// <summary> /// 2014-6-6 /// </summary> / ...
- ADO.NET和ORACLE操作数据库传参数赋值的方式
在使用.Net使用OracleParameter进行Oracle数据库操作的时候,因为Oracle和SQLServer针对查询参数化的语法不同, 在操作SQLServer的时候使用的是@Paramet ...
- css.day04
1. box 盒子模型 <p> <span> <hr/> <div> css+ div p span css+ xhtml b ...
- Python 时间函数
时间的运用 #coding=utf-8 #!user/bin/python import time import calendar ticks = time.asctime(time.localtim ...
- 读写XML
XML: 代码: //实例化 XmlDocument xmldc = new XmlDocument(); //加载xml文件,参数是路径. xmldc.Load("C:/Users/Des ...
- StartCoroutine/StopCoroutineInvoke
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_Coroutine.html using UnityEngine; us ...
- Android Studio删除Project
最直截了当的方法是在Project所在目录直接删除整个Project,然后再次打开Android Studio的欢迎界面中把光标移到你的Project上,然后按键盘上的Delete键即可! 参考自st ...