1160

算是模版了 没什么限制 结束输出就行了

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stdlib.h>
using namespace std;
#define N 1010
#define M 15010
struct node
{
int x,y,len;
}p[M];
int fa[N];
int find(int x)
{
if(fa[x]!=x)
fa[x] = find(fa[x]);
return fa[x];
}
bool cmp(node a,node b)
{
return a.len<b.len;
}
int main()
{
int i,j,n,m;
scanf("%d%d",&n,&m);
for(i =; i <= n ; i++)
fa[i] = i;
for(i = ; i <= m ; i++)
{
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].len);
}
sort(p+,p+m+,cmp);
int s = ,maxz=;
for(i = ; i <= m&&s<n- ; i++)
{
int tx = find(p[i].x),ty = find(p[i].y);
if(tx!=ty)
{
fa[tx] = ty;
s++;
maxz = max(maxz,p[i].len);
}
}
printf("%d\n",maxz);
printf("%d\n",i-);
for(j = ; j < i ; j++)
printf("%d %d\n",p[j].x,p[j].y);
return ;
}

1160. Network(最小生成树)的更多相关文章

  1. URAL 1160 Network(最小生成树)

    Network Time limit: 1.0 secondMemory limit: 64 MB Andrew is working as system administrator and is p ...

  2. [poj2349]Arctic Network(最小生成树+贪心)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17758   Accepted: 5646 D ...

  3. BZOJ 3732: Network 最小生成树 倍增

    3732: Network 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3732 Description 给你N个点的无向图 (1 &l ...

  4. POJ 2349 Arctic Network (最小生成树)

    Arctic Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  5. ZOJ1586——QS Network(最小生成树)

    QS Network DescriptionIn the planet w-503 of galaxy cgb, there is a kind of intelligent creature nam ...

  6. TZOJ 2415 Arctic Network(最小生成树第k小边)

    描述 The Department of National Defence (DND) wishes to connect several northern outposts by a wireles ...

  7. ZOJ1586:QS Network (最小生成树)

    QS Network 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1586 Description: In th ...

  8. poj2349 Arctic Network - 最小生成树

    2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...

  9. POJ-1861,Network,最小生成树水题,,注意题面输出有问题,不必理会~~

    Network Time Limit: 1000MS   Memory Limit: 30000K          Special Judge http://poj.org/problem?id=1 ...

随机推荐

  1. 关于const

    1.顶层const和底层const const修饰的对象本身是常量,则为顶层const,否则为底层const 如: const int a=10;        //a是int常量,顶层const i ...

  2. Java中List和ArrayList的区别

    List:是一个有序的集合,可以包含重复的元素.提供了按索引访问的方式.它继承 Collection.List有两个重要的实现类:ArrayList 和 LinkedListArrayList:我们可 ...

  3. jquery 取值赋值

    <input type="text" id="range_complete" /> $('#range_complete').val();//取值 ...

  4. For和While在C和MATLAB中的区别——MATLAB的大坑

    For和while是常见的循环关键字,在许多语言中都是通用的.但是想必不是所有人,都被其中的区别困扰过,尤其是MATLAB“程序员”. x=[,,,,,,]; i=; while i<=leng ...

  5. oracle 判断是否数字 正则表达式法

     SELECT '-100'    FROM dual   WHERE REGEXP_LIKE('-100','(^[+-]?\d{0,}\.?\d{0,}$)'); REGEXP_LIKE 用法: ...

  6. C# 该行已经属于另一个表 的解决方法[转]

    该文转自:http://blog.sina.com.cn/s/blog_48e4c3fe0100nzs6.html DataTable dt = new DataTable(); dt = ds.Ta ...

  7. UVA 10954 Add All 哈夫曼编码

    题目链接: 题目 Add All Time Limit:3000MS Memory Limit:0KB 问题描述 Yup!! The problem name reflects your task; ...

  8. mysql之sql语句导入与导出讲解

    导出SQL:mysqldump -u root -p 数据库名 [表名1 表名2] > 输出地址其中表名可选 本机测试实例:

  9. uva 1368

    简单的贪心 ~ #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...

  10. What is Object Oriented Design? (OOD)

    Object Oriented Design is the concept that forces programmers to plan out their code in order to hav ...