题意:给你n个点  n-1行每行代表的是这个点到给定点的距离   求最短路

解题思路:开始是用getchar  发现runtime error   后来用了  字符串  才改进了   裸Kruskal

解题代码:

poj 1251

// File Name: c.cpp
// Author: darkdream
// Created Time: 2013年04月24日 星期三 22时43分39秒

#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>using namespace std;int p[100005];
int v[100005];
int u[100005];
int r[100005];
int w[100005];
int find(int x)
{return  p[x] == x? x:p[x] =find(p[x]);
}
int cmp(const int i, const int j )
{return w[i] < w[j];
}
char str[100];
int main(){int n ;while(scanf("%d",&n) !=  EOF){memset(p,0,sizeof(p));memset(r,0,sizeof(r));memset(v,0,sizeof(v));memset(u,0,sizeof(u));memset(w,0,sizeof(w));if(n == 0 )break;int m = 0;for(int s = 1;s <n; s++){  char c;int k ;scanf("%s",str);c = str[0];scanf("%d",&k);for(int i = 1;i <= k ; i ++){char tempc;int temp;scanf("%s",str);tempc = str[0];scanf("%d",&temp);v[++m] = c-'A' +1;u[m] = tempc -'A'+1;w[m] = temp;}}//for(int i =1;i <= m ;i ++)//    printf("%d %d\n",v[i],u[i]);for(int i = 1;i <=n ;i ++)p[i] = i ;for(int i = 1 ;i <= m  ;i ++)r[i] = i ;sort(r+1,r+m+1,cmp);//    for(int i =1 ;i <= m; i ++)//        printf("%d\n",r[i]);int ans = 0;for(int i =1 ;i <= m;i ++){int e = r[i];int x = find(v[e]); int y = find(u[e]);//int x = 0 , y = 0;if(x != y){ans += w[e];p[x] = y;}}printf("%d\n",ans);}return 0;
}

转载于:https://www.cnblogs.com/zyue/archive/2013/04/25/3042355.html

POJ 1251 Jungle Roads相关推荐

  1. poj 1251 Jungle Roads

    #include <iostream> // 最小生成树kruskal算法#include <algorithm>using namespace std;const int m ...

  2. POJ - 1251(最小生成树.krustal)

    题目链接:http://poj.org/problem?id=1251 题目: Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total ...

  3. Jungle Roads丛林道路(最小生成树PrimKruskal算法)

    Jungle Roads丛林道路 POJ - 1251 目录 Jungle Roads丛林道路 题意描述 Kruskal算法解题思路 Kruskal AC代码 Prim 解题思路 AC代码 The H ...

  4. HDU 1301 Jungle Roads(裸最小生成树)

    题目链接 今天做了好几个模版最小生成树...贴一个kurskral. 1 /* 2 HDU 1301 Jungle Roads 3 最小生成树Kurskal模版 4 */ 5 #include < ...

  5. 【HDU - 1301】Jungle Roads(并查集+最小生成树)(内附最小生成树两种算法 克鲁斯特尔算法amp;amp;普里姆算法)

    题干: Jungle Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDU 1815, POJ 2749 Building roads(2-sat)

    HDU 1815, POJ 2749 Building roads 题目链接HDU 题目链接POJ 题意: 有n个牛棚, 还有两个中转站S1和S2, S1和S2用一条路连接起来. 为了使得随意牛棚两个 ...

  7. * poj 1251 JungleRoad 最小生成树 Kruskal算法、Prim算法

    文章目录 Kruskal算法 模板:https://blog.csdn.net/Rain722/article/details/65642992 Prim算法 模板: poj 1251 JungleR ...

  8. Jungle Roads//最小生成树kruskal

    题目: Jungle Roads Time Limit: 2 Seconds      Memory Limit: 65536 KB The Head Elder of the tropical is ...

  9. 题目1154:Jungle Roads

    题目描述: The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money ...

最新文章

  1. 万物共享的物联网架构
  2. android studio第一次配置flutter(2019年12月)
  3. 世界不乏爱因斯坦,缺乏的适合他茁壮成长的环境
  4. linux sort命令 性能,linux sort 命令详解
  5. TCP/IP详解 笔记十三
  6. Python打包文件为exe,PyInstaller应用
  7. JDBC连接数据库的8个步骤
  8. 【ubuntu】更换下载源
  9. 中考计算机考试exce,中考信息技术EXCEL操作.doc
  10. 学渣上手 LaTeX 完成毕业论文
  11. PreparedStatement 不定参数处理
  12. python实现具有删除空格、英文标点替换、英文单词大写等功能的文字排版工具
  13. 来,让我用Python给你算一命
  14. SSS1629USB麦克风方案设计原理
  15. 基于Java的网上手机销售系统的设计与实现(附:源码 论文 sql文件 部署视频)
  16. android的虚拟机
  17. 【三种常见架构开发模式:MVC、MVP、MVVM】
  18. 对等网络(P2P)--网络大典
  19. android 查找联系人方法(支持首拼,全拼,英文)
  20. 这家公司只有1个人,年赚一个亿

热门文章

  1. zynq学习03 zynq中三种实现GPIO的方式
  2. 图像转文字(分类识别等),文字转图片,实际需要的过程
  3. 12. MySQL简单使用
  4. Python 3下Matplotlib画图中文显示乱码的解决方法
  5. HotSpot虚拟机对象的创建过程
  6. 查看oralce的版本及安装了哪些选项
  7. zabbix 监控 elasticsearch
  8. 构造函数,析构函数,对象连的简单应用
  9. 也说_T、_TEXT、TEXT、L
  10. Sql Server系列:触发器