题目1154:Jungle Roads
来源:互联网 发布:有线网络信号增强器 编辑:程序博客网 时间:2024/06/18 05:29
#include "iostream"#include "stdio.h"#include <vector>#include <cstring>#include <algorithm>#include <string>#include <string.h>#include <stack>#include <ctype.h>#include <functional>#include <math.h>using namespace std;//1154int n,size,cn,d;char c1,c2;char t[127];struct edge{ char fo,to; int dis; bool operator < (const edge &a)const { return dis<a.dis; }}edge[1000];char findRoot(char a){ if(t[a]==a) return a; else{ char tmp=findRoot(t[a]); t[a]=tmp; return tmp; }}int main(){ //freopen("input.txt","r",stdin); while(cin>>n && n!=0 ){ n--;size=0; while(n--){ cin>>c1; cin>>cn; if(cn==0) continue; while(cn--){ cin>>c2>>d; edge[size].fo=c1; edge[size].to=c2; edge[size++].dis=d; } } sort(edge,edge+size); for(int i='A';i<='Z';i++) t[i]=i; int res=0; for(int i=0;i<size;i++){ c1=findRoot(edge[i].fo); c2=findRoot(edge[i].to); if(c1!=c2){ t[c1]=c2; res+=edge[i].dis; } } cout<<res<<endl; } return 0;}/************************************************************** Problem: 1154 User: cust123 Language: C++ Result: Accepted Time:0 ms Memory:1528 kb****************************************************************/
0 0
- 题目1154:Jungle Roads
- 题目1154:Jungle Roads
- 题目1154:Jungle Roads
- 题目1154:Jungle Roads
- 题目1154:Jungle Roads
- Jobdu 题目1154:Jungle Roads
- 题目1154:Jungle Roads:最小生成树
- 九度 题目1154:Jungle Roads
- 九度OJ 题目1154:Jungle Roads
- 九度题目1154:Jungle Roads
- 九度 oj 题目1154:Jungle Roads
- 题目1154:Jungle Roads 九度OJ
- Jungle Roads
- Jungle Roads
- Jungle Roads
- Jungle Roads
- Jungle Roads
- Jungle Roads
- [JZOJ5073]【GDOI2017第三轮模拟day1】影魔
- Neural Module Networks
- 配置伪分布式时的问题”JAVA_HOME is not set and could not be found“解决方法
- redis.conf 常用配置文件详解
- 数据库基础知识7
- 题目1154:Jungle Roads
- 欢迎使用CSDN-markdown编辑器
- 【一步一个脚印】Tomcat+MySQL为自己的APP打造服务器(3-3)Json数据交互
- 使用virtualenv和virtualenvwrapper
- spring 加载配置文件的方式
- 【cc2541历程】替换协议栈的LCD文件
- 基于 vs2013 + caffe 的 人脸图像 vgg 特征提取
- opencv从零开始——0. 快速上手
- 集群运行spark时出现的问题