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

#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. DOS批处理命令-SET命令

    SET是专门用来创建.设置.查看或删除环境变量. 总结了下,SET的使用语法一般有下面几种 1.SET 变量名=变量值 这边有一点要注意的,就是变量名和变量值中间的等号两端不需要也不能有空格 看看下面 ...

  2. 博客迁到CSDN

    之前一直是博客园和CSDN博客同步更新 现在不在博客园继续写博客,十一国庆节假后只用CSDN博客了.祝各位访客国庆节快乐! CSDN博客地址: http://blog.csdn.net/it_liuc ...

  3. c#winform音乐制作软件

    C#音乐播放器 这个音乐播放器是winform 功能有:(括号中是值得提高的部分) 1:登陆提示(查询数据库) 2:皮肤换肤的功能(能右键或者通过按键就能实现) 3:图片的轮换(图片的地址从数据库中抽 ...

  4. CAF(C++ actor framework)(序列化之类,无需序列化,直接传)(二)

    昨天讲了Struct,还是不够满意,毕竟C++里面类用的比较多嘛,那就先上个类, 这段代码是我稍微改编了一下的结果.都是最基本的用法. #include <utility> #includ ...

  5. opencv 手写选择题阅卷 (四)Android端 手机应用开发

    opencv 手写选择题阅卷 (四)Android 手机应用开发 在PC端把代码调通以后开始开发Android 手机应用,因为主要功能代码为C++代码,所以需要通过NDK编译,JAVA通过JNI方式调 ...

  6. d3 之值域映射

    <html> <head> <meta charset="utf-8"> <title>d3研究室</title> &l ...

  7. 关于mysql group_concat 不能显示为空的列的其他信息

    今天做项目遇到一个问题,百度好久都没找到问题所在 是酱紫的,一张表 关联的表 然后我用sql语句查询 point.pid,point.pname,GROUP_CONCAT(downsite.pname ...

  8. DEDECMS中,获取面包屑导航

    获取面包屑导航 {dede:field name='position'/} {dede:field.position/}

  9. Linux C 程序 获取目录信息(16)

    4.获取当前目录getcwd 会将当前工作目录绝对路径复制到参数buf所指的内存空间5.设置工作目录chdir6.获取目录信息opendir打开一个目录readdir读取目录中的内容  读取目录项信息 ...

  10. jquery + json 操作

    jquery 读取集合对象多是要与json进行解析操作的,以下自己经过多方资料查找,终于有一套自己的方式组合.  1.首先创建web services或一般处理程序,用于显示获取Datatable对象 ...