最小生成树  第一次敲 套用几个函数 其实挺容易的

#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的更多相关文章

  1. URAL 1160 Network(最小生成树)

    Network Time limit: 1.0 secondMemory limit: 64 MB Andrew is working as system administrator and is p ...

  2. XDU 1160 - 科协的数字游戏I

    Problem 1160 - 科协的数字游戏I Time Limit: 1000MS   Memory Limit: 65536KB   Difficulty: Total Submit: 184   ...

  3. HDU 1160 DP最长子序列

    G - FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  4. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  5. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  6. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  7. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  8. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  9. 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 ...

随机推荐

  1. android操作通讯录的联系人

    界面配置文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     and ...

  2. ORA-00001: unique constraint (...) violated解决方案

    ORA-00001: unique constraint (...) violated 的解决方案 今天往Oracle数据库里插入数据一条记录的时候,报错了, 控制台抛出异常:违反唯一性约定, 我以为 ...

  3. [Bootstrap]全局样式(三)

    表格 1.基本类  .table  {width/margin-bottom/}  {padding/border-top} e.g.:<table class="table" ...

  4. Z-Stack内部API 小结

    Z-Stack是TI推出的全功能ZigBee协议栈,通过了ZigBee联盟的兼容性平台测试,包含如下几个组件. 1. HAL,硬件抽象层 2. OSAL,操作系统抽象层 3. ZigBee Stack ...

  5. c++ algorithm 的用法

    1 , accumulate()template<class _II, class _Ty> inline_Ty accumulate(_II _F, _II _L, _Ty _V){fo ...

  6. java应用uploadify 3.2丢失session

    java应用uploadify 3.2丢失session http://c-bai.iteye.com/blog/1829269 uploadify上传用的是一个flash插件. flash中有个bu ...

  7. Editplus 中将文本换行替换为<p>标签的正则表达式

    在Editplus.Notepad++编辑器里文本直接复制到在线编辑器里是不带<p>标签的,只是简单的将换行"\n"替换为"<br />" ...

  8. Spark Streaming揭秘 Day27 Job产生机制

    Spark Streaming揭秘 Day27 Job产生机制 今天主要讨论一个问题,就是除了DStream action以外,还有什么地方可以产生Job,这会有助于了解Spark Streaming ...

  9. 64位Python安装PIL

    写个小程序需要安装PIL,但是官网只有32位,无法找到64位安装路径.根据网上教程自行编译,但是由于VS版本问题总是提示“Python error: Unable to find vcvarsall. ...

  10. python安装与环境变量配置

    默认情况下,在windows下安装python之后,系统并不会自动添加相应的环境变量.此时不能在命令行直接使用python命令. 1. 首先需要在系统中注册python环境变量:假设python的安装 ...