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 ...
随机推荐
- 10.30Daily Scrum
出席人员 任务分配完成情况 明天任务分配 王皓南 研究代码,讨论实现方法及实现的动能 研究代码,学习相应语言,讨论设计思路 申开亮 研究代码,讨论实现方法及实现的动能 研究代码,学习相应语言,讨论设计 ...
- 例题-文件系统的放大 (LVM):
纯粹假设的,我们的 /home 不够用了,你想要将 /home 放大到 7GB 可不可行啊? 答: 因为当初就担心这个问题,所以 /home 已经是 LVM 的方式来管理了.此时我们要来瞧瞧 VG 够 ...
- 在一个Activity里面的TextView上面添加网页链接,启动后到另一个Activity里面!
可以添加很多的属性,样式或者是什么的,目前要完成的功能是 点击TextView里面的某个文字链接,进入另外一个Activity里面!例如你可以做微博里面的 @XXX: 点击后进入他的个人主页! 下面都 ...
- 【Vijos】【1923】漫长的等待
可持久化线段树 这次是询问一段区间内权值 在给定范围内的点的数量,同样是可持久化线段树简单操作…… //Vijos 1923 #include<vector> #include<cs ...
- [转载]Spring Java Based Configuration
@Configuration & @Bean Annotations Annotating a class with the @Configuration indicates that the ...
- Core Java Interview Question Answer
This is a new series of sharing core Java interview question and answer on Finance domain and mostly ...
- C#委托及事件
转载:http://www.cnblogs.com/warensoft/archive/2010/03/19/1689806.html C#委托及事件 在C#中,委托(delegate)是一种引用类型 ...
- REST_FRAMEWORK加深记忆-第二次练习官方文档2
优化前和优化后的代码,融在一起,能看看进化的过程. MODELS.PY from django.db import models from pygments.lexers import get_all ...
- hdu 4699 Editor 模拟栈
思路:刚开始用STL中的栈,一直RE……,之后改为手动模拟栈操作,在注意点细节就可以了!!! 代码如下: #include<cstdio> #include<cstring> ...
- cojs 西瓜 解题报告
首先我们要知道pick公式 设二维平面内任意多边形面积为S 设多边形内部整点数为a 设多边形边界的整点数为b 则满足S=a+b/2-1 变形得a=S-b/2+1 由期望的线性性质我们把问题转化为 1. ...