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 ...
随机推荐
- IIS6批量转移网站
IIS6.0有个导出配置的功能,但你却找不到界面上的直接导入配置功能,需要用到操作系统自带的iiscnfg.vbs脚本. 1.导出当前的IIS网站配置 打开Internet信息服务(IIS)---&g ...
- IUSR和IIS_IUSRS
在早期的IIS版本中,随着IIS的安装,系统会创建一个IUSR_MachineName用户.IIS启用匿名访问,就是通过此用户进行身份认证的,包括FTP匿名访问,HTTP匿名访问. 在创建IUSR ...
- SQL Server的三种物理连接之Merge join(二)
简介 merge join 对两个表在连接列上按照相同的规则排序,然后再做merge,匹配的输出. 下面这个动态图展示了merge join的详细过程. merge join示例 创建两个表 IF O ...
- C# DateTime格式化
DateTime. ToString() -- :: ToBinary() - ToFileTime() ToFileTimeUtc() ToLocalTime() -- :: ToLongDateS ...
- PHP之HMVC
HMVC(Hierarchical-Model-View-Controller),也可以叫做 Layered MVC.顾名思义,就是按等级划分的 MVC 模式,简单的解释就是把MVC又细分成了多个子 ...
- mysql 强制走索引
查询是数据库技术中最常用的操作.查询操作的过程比较简单,首先从客户端发出查询的SQL语句,数据库服务端在接收到由客户端发来的SQL语句后, 执行这条SQL语句,然后将查询到的结果返回给客户端.虽然过程 ...
- System.Windows.Forms.Timer
一.主要属性.方法和事件 Windows 窗体 Timer 是定期引发事件的组件.该组件是为 Windows 窗体环境设计的. 时间间隔的长度由 Interval 属性定义,其值以毫秒为单位.若启用了 ...
- 用angular实时获取本地localStorage数据,实现一个模拟后台数据登入的效果
研究了一上午,终于做出了,实时获取本地localStorage来模拟注册登入~~~ <!DOCTYPE html><html><head lang="en&qu ...
- [GeekBand] 探讨C++新标准之新语法——C++ 11~14
一. 可变参数模板(Variadic Templates) 在C++11中,出现了参数数目可变的模板,这部分在之前C++高级编程的时候就有学习到. 其实,在C中就有类似的设定.最常用的printf() ...
- QMessageBox 在MAC下更加自然
说明 在MAC写过QT程序的程序员应该都知道,QT默认的QMessageBox没有MAC系统的效果,在网上找到了一篇关于这方面的文章,但是这篇文章写的有个缺点,就是使用信号的方式,使用起来很不方便. ...