ural 1160
最小生成树 第一次敲 套用几个函数 其实挺容易的
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
struct node
{
int u,v,w;
void f(int a, int b, int c)
{
u = a;
v = b;
w = c;
}
bool operator < (const node & e) const
{
return w < e.w;
}
};
vector<node>q,qq;
int p[2000],r[2000]; int findd(int x)
{
return p[x] == x ? x : p[x] = findd(p[x]);
}
int main()
{
int n,m;
node cc;
scanf("%d%d",&n,&m);
for(int i = 0; i < m; i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
cc.f(a,b,c);
q.push_back(cc);
}
sort(q.begin(), q.end());
int ans = 0;
for(int i = 0; i <= n; i++)
p[i] = i;
for(int i = 0; i < m; i++)
{
int x = findd(q[i].u), y = findd(q[i].v);
if(x != y)
{
ans = q[i].w;
qq.push_back(q[i]);
p[x] = y;
}
}
printf("%d\n",ans);
int len = qq.size();
printf("%d\n",len);
for(int i = 0; i < len; i ++)
printf("%d %d\n",qq[i].u,qq[i].v);
return 0;
}
ural 1160的更多相关文章
- URAL 1160 Network(最小生成树)
Network Time limit: 1.0 secondMemory limit: 64 MB Andrew is working as system administrator and is p ...
- XDU 1160 - 科协的数字游戏I
Problem 1160 - 科协的数字游戏I Time Limit: 1000MS Memory Limit: 65536KB Difficulty: Total Submit: 184 ...
- HDU 1160 DP最长子序列
G - FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
随机推荐
- 使用Win7+IIS7发布网站或服务步骤
1.安装IIS服务:控制面板=>程序=>打开或关闭WINDOWS 功能=>Internet 信息服务=>WEB服务管理器全选√ 和万维网服务:应用程序开发功能: 2.打开IIS ...
- 关于FPGA(verilog)电平检测模块的易错点分析
reg F1,F2; // F2 Previous State, F1 Current State always@(posedge CLK or negedge RSTn) if(!RSTn) beg ...
- PERL 脚本
PERL: Practical Extraction and Report Language 参考文档 1.Perl 5 version 24.0 documentation
- 翻转单词顺序VS左旋转字符串
题目:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变.句子中单词以空格符隔开.为简单起见,标点符号和普通字母一样处理.例如输入“I am a student.”,则输出“student ...
- 第七章 探秘Qt的核心机制-信号与槽
第七章 探秘Qt的核心机制-信号与槽 注:要想使用Qt的核心机制信号与槽,就必须在类的私有数据区声明Q_OBJECT宏,然后会有moc编译器负责读取这个宏进行代码转化,从而使Qt这个特有的机制得到使用 ...
- GridView - javascript 触发后台 OnSelectedIndexChanged
1.ASPX <asp:GridView ID="gdvDealers" runat="server" AutoGenerateColumns=" ...
- 中科红旗倒下,谁来挑战windows
中科红旗解散 国产操作系统从此梦断 2月10日,关门上锁的中科红旗北京总部大门上粘贴了一张最新公告,这张公告彻底击破了那些仍然坚守公司工作的员工“拯救中国红旗”的希望.该公告称:因北京中科红旗软件技术 ...
- [译]servlet3.0与non-blocking服务端推送技术
Non-blocking(NIO)Server Push and Servlet 3 在我的前一篇文章写道如何期待成熟的使用node.js.假定有一个框架,基于该框架,开发者只需要定义协议及相关的ha ...
- linux关闭服务的方法
本文介绍下,在linux下关闭服务的方法,主要学习chkconfig的用法,有需要的朋友参考下. 先来看一个在linux关闭服务的例子,例如,要关闭sendmail服务,则可以按如下操作. 例1, 复 ...
- Centos7搭建集中式日志系统
在CentOS7中,Rsyslong是一个集中式的日志收集系统,可以运行在TCP或者UDP的514端口上. 目录 开始之前 配置接收日志的主机 配置发送日志的主机 日志回滚 附件:创建日志接收模板 ...