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. 3242: [Noi2013]快餐店 - BZOJ

    Description 小T打算在城市C开设一家外送快餐店.送餐到某一个地点的时间与外卖店到该地点之间最短路径长度是成正比的,小T希望快餐店的地址选在离最远的顾客距离最近的地方. 快餐店的顾客分布在城 ...

  2. sed 详解

    sed 详解 1.简介 sed是非交互式的编辑器.它不会修改文件,除非使用shell重定向来保存结果.默认情况下,所有的输出行都被打印到屏幕上. sed编辑器逐行处理文件(或输入),并将结果发送到屏幕 ...

  3. Smarty插件简单开发

    smarty的插件相当简单,你的网站经常会用到一些特定的Url或Controller或Action的路由地址的动态生成,通过smarty插件方式可以很轻松的实现. 在smarty/plugins目录下 ...

  4. 【BZOJ】【1532】【POI2005】Kos-Dicing

    网络流/二分法 最大值最小……直接做不太好做的时候就可以用二分+判定来搞. 这题我们就也可以二分最大胜场v,那么怎么来判定呢?首先我们发现:每场比赛要么A赢,要么B赢,这一点跟二分图匹配非常类似,那么 ...

  5. WinForm点击按钮在对应的panel里画图

    panel在form1里,button在form1上方,panel在下面. 主要是在button1的click时间获取panel的画笔. 下面的不行,在panel里获取画笔,然后传到button1,根 ...

  6. [转载]C#中int和IntPtr相互转换

    方法一. int转IntPtr int i = 12;           IntPtr p = new IntPtr(i); IntPtr转int int myi = (int)p;         ...

  7. ZendStudio中设置SVN:ignore

    使用ZendStudio开发SVN中的代码时,经常容易将 .project..settings..buildpath 这类的zend的工程文件提交上去,非常麻烦,有几种方法可以去掉这个麻烦. 1.在Z ...

  8. LOGSTASH再入门第一发

    慢慢弄起来... 前年搞过,现在生疏了,再慢慢拾起来吧. 一些URL: https://www.elastic.co/downloads/logstash https://www.elastic.co ...

  9. hdu1116

    http://acm.hdu.edu.cn/showproblem.php?pid=1116 #include<stdio.h> #include<math.h> #inclu ...

  10. 【转】Cygwin访问Windows驱动器

    From:http://www.cygwin.cn/site/info/show.php?IID=1000 由于自己的项目需要使用Linux内核,所以自己在windows下安装了一个Linux虚拟机! ...