1160. Network(最小生成树)
算是模版了 没什么限制 结束输出就行了
#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(最小生成树)的更多相关文章
- URAL 1160 Network(最小生成树)
Network Time limit: 1.0 secondMemory limit: 64 MB Andrew is working as system administrator and is p ...
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- BZOJ 3732: Network 最小生成树 倍增
3732: Network 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3732 Description 给你N个点的无向图 (1 &l ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- ZOJ1586——QS Network(最小生成树)
QS Network DescriptionIn the planet w-503 of galaxy cgb, there is a kind of intelligent creature nam ...
- TZOJ 2415 Arctic Network(最小生成树第k小边)
描述 The Department of National Defence (DND) wishes to connect several northern outposts by a wireles ...
- ZOJ1586:QS Network (最小生成树)
QS Network 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1586 Description: In th ...
- poj2349 Arctic Network - 最小生成树
2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...
- POJ-1861,Network,最小生成树水题,,注意题面输出有问题,不必理会~~
Network Time Limit: 1000MS Memory Limit: 30000K Special Judge http://poj.org/problem?id=1 ...
随机推荐
- C# Windows - SDI和MDI应用程序
生成MDI应用程序 MDI应用程序至少要由两个截然不同的窗口组成.第一个窗口叫做MDI容器(Container),可以在容器中显示的窗口叫做MDI子窗口. 要把应用程序的主窗口从一个窗体改为MDI容器 ...
- .net 科学类型相关问题
Q:如果我要把使用科学记数法表示的string转换为int又该如何呢? A:你可以通过把NumberStyles.AllowDecimalPoint | NumberStyles.AllowExpon ...
- bnuoj 33648 Neurotic Network(树形模拟题)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=33648 [题解]:结果先对MOD*2取模,才能得到结果是否是正确的奇偶问题,得到最后结果之后再对MO ...
- MYSQL存储过程实现in传入参数 where in('1','2')
android 服务器端开发中遇到这么一个问题: 突然发现将字符串传入到存储过程,参数为 '1','2' ,竟然执行无效 所以看到网上有在存储过程中直接拼凑sql的代码,今天也试了一下,可以执行了, ...
- android控件---spinner
spinner下拉列表框的列表项有两种配置方式: 1.通过资源文件配置,通过在values种的xml,比如strings.xml中使用<string-array>元素添加制定列表项内容,然 ...
- 2014 Multi-University Training Contest 2
官方解题报告:http://blog.sina.com.cn/s/blog_a19ad7a10102uyet.html ZCC Loves Intersection ZCC Loves COT 首先考 ...
- [转载]AFX_MANAGE_STATE关于资源切换
应用程序进程本身及其调用的每个DLL模块都具有一个全局唯一的HINSTANCE句柄,它们代表了DLL或EXE模块在进程虚拟空间中的起始地址.进程本身的模块句柄一般为0x400000,而DLL模块的缺省 ...
- [设计模式] 5 单例模式 singleton
转处 http://blog.csdn.net/wuzhekai1985 软件领域中的设计模式为开发人员提供了一种使用专家设计经验的有效途径.设计模式中运用了面向对象编程语言的重要特性:封装.继承.多 ...
- uva 307
排序之后再剪枝,有点神 #include <cstdio> #include <cstdlib> #include <cmath> #include <map ...
- Unity Editor not displaying Android textures properly
最近入门学习shader,语法倒没什么,有一个奇怪的问题,如果把编译平台从pc转换为android模式的话,如果你的shader 带 Normal Mapping 的 话,效果和android上的真机 ...