Jungle Roads POJ - 1251 模板题
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=0x3f3f3f3f;
int p[];
struct edge{
int a,b,w;
}e[];
bool cmp(edge a,edge b)
{
return a.w<b.w;
}
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
int main()
{
int n;
while(cin>>n&&n)
{
for(int i=;i<;i++)
p[i]=i;
int k=;
for(int i=;i<n-;i++)
{
char str1[];
int m;
cin>>str1>>m;
for(int j=;j<m;j++,k++)
{
char str2[];
int t;
cin>>str2>>t;
e[k]={str1[]-'A',str2[]-'A',t};
}
}
sort(e,e+k,cmp);
int ans=;
for(int i=;i<k;i++)
{
int a=find(e[i].a);
int b=find(e[i].b);
int w=e[i].w;
if(a!=b)
{
ans+=w;
p[a]=b;
}
}
cout<<ans<<endl;
} }
Jungle Roads POJ - 1251 模板题的更多相关文章
- (最小生成树) Jungle Roads -- POJ -- 1251
链接: http://poj.org/problem?id=1251 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2177 ...
- A - Jungle Roads - poj 1251(简单)
想必看这道题的时候直接看数据还有那个图就能明白什么意思吧,说的已经很清楚了,每个点都有一些相连的点和权值,求出来如果连接所有点,最小的权值是多少,赤裸裸的最小生成树... ************** ...
- A Plug for UNIX POJ - 1087(模板题 没啥好说的。。就用了一个map)
题意: 几种插头,每一种都只有一个,但有无限个插头转换器,转换器(a,b) 意味着 可以把b转换为a,有几个设备,每个设备对应一种插头,求所不能匹配插头的设备数量 这个题可以用二分图做 , 我用的是最 ...
- HDU 2988 Dark roads(kruskal模板题)
Dark roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 【HDU1301】Jungle Roads(MST基础题)
爽爆.史上个人最快MST的记录7分40s..一次A. #include <iostream> #include <cstring> #include <cstdlib&g ...
- poj 1986tarjan模板题
#include<iostream> #include<vector> using namespace std; const int N=40010; int pre[N];/ ...
- poj 1330lca模板题离线算法
#include<iostream> #include<vector> using namespace std; const int MAX=10001; int pre[MA ...
- 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 ...
随机推荐
- 使用Vue.prototype在vue中注册和使用全局变量
在main.js中添加一个变量到Vue.prototype Vue.prototype.$appName = 'My App' 这样 $appName 就在所有的 Vue 实例中可用了,甚至在实例被创 ...
- Apache Solr JMX服务 RCE 漏洞复现
Apache Solr JMX服务 RCE 漏洞复现 ps:Apache Solr8.2.0下载有点慢,需要的话评论加好友我私发你 0X00漏洞简介 该漏洞源于默认配置文件solr.in.sh中的EN ...
- string的基本操作
在C++中,string 可以来定义一个字符串,用之前得调用下相应的库 #include<string> . 可以不用初始化字符串容量大小,系统会根据后续的赋值自动安排其容量大 ...
- c语言心形告白代码实现
c语言心形告白代码实现 1.彩色告白 include<stdio.h> include<math.h> include<windows.h> include< ...
- R语言入门:向量的运算
向量之间的加减乘除运算: > x <- 1 > x [1] 1 2 3 4 5 6 7 8 9 10 > x=x+1 > x [1] 2 3 4 5 6 7 8 9 10 ...
- mysql设置编码格式--支持中文
创建table的时候就使用utf8编码 在每次创建表的时候都在最后加上 character set = utf8就可以很好的支持中文 create table xxx ( id int auto_in ...
- 「Kafka」Kafka中offset偏移量提交
在消费Kafka中分区的数据时,我们需要跟踪哪些消息是读取过的.哪些是没有读取过的.这是读取消息不丢失的关键所在. Kafka是通过offset顺序读取事件的.如果一个消费者退出,再重启的时候,它知道 ...
- 深度(deepin)系统不能ssh root用户登录
vi /etc/ssh/sshd_config找到这一部分信息刚进去信息应该是这样 # Authentication: #LoginGraceTime 2m #PermitRootLogin proh ...
- opencv二值化的cv2.threshold函数
(一)简单阈值 简单阈值当然是最简单,选取一个全局阈值,然后就把整幅图像分成了非黑即白的二值图像了.函数为cv2.threshold() 这个函数有四个参数,第一个原图像,第二个进行分类的阈值,第三个 ...
- 安装Kubernetes到CentOS(Minikube)
运行环境 系统版本:CentOS Linux release 7.6.1810 (Core) 软件版本:Docker-ce-18.06.0.Kubectl-1.15.0.Kubernetes-v1.1 ...