题目链接:

http://www.lydsy.com/JudgeOnline/problem.php?id=1083

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std; const int maxn = ;
const int maxm = maxn*maxn; struct Edge {
int u, v, w;
bool operator < (const Edge& tmp) const {
return w < tmp.w;
}
}egs[maxm]; int n, m; int fat[maxn];
int Find(int x) {
return fat[x] = fat[x] == x ? x : Find(fat[x]);
} int main() {
while (scanf("%d%d", &n, &m) == ) {
for (int i = ; i <= n; i++) fat[i] = i;
for (int i = ; i < m; i++) {
scanf("%d%d%d", &egs[i].u, &egs[i].v,&egs[i].w);
}
sort(egs, egs + m);
int ma = -;
for (int i = ; i < m; i++) {
int pu = Find(egs[i].u);
int pv = Find(egs[i].v);
if (pu != pv) {
ma = max(ma, egs[i].w);
fat[pv] = pu;
}
}
printf("%d %d\n", n - , ma);
}
return ;
}

BZOJ 1083: [SCOI2005]繁忙的都市 裸的最小生成树的更多相关文章

  1. BZOJ 1083: [SCOI2005]繁忙的都市【Kruscal最小生成树裸题】

    1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2925  Solved: 1927[Submit][Sta ...

  2. Bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)

    Bzoj 1083: [SCOI2005]繁忙的都市 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 此题是最小瓶颈生成树的裸题. ...

  3. BZOJ 1083: [SCOI2005]繁忙的都市(MST)

    裸的最小生成树..直接跑就行了 ---------------------------------------------------------------------- #include<c ...

  4. BZOJ 1083: [SCOI2005]繁忙的都市 kruskal

    1083: [SCOI2005]繁忙的都市 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1083 Description 城市C是一个非 ...

  5. BZOJ 1083 [SCOI2005]繁忙的都市

    1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1664  Solved: 1080[Submit][Sta ...

  6. BZOJ 1083 [SCOI2005]繁忙的都市 (最小生成树裸题无重边) 超简单写法!!

    Description 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口 ...

  7. bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 思路:连接所有点,肯定最少是需要n-1条边的,也就是写个最小生成树,记得保存下最大的权 ...

  8. BZOJ(5) 1083: [SCOI2005]繁忙的都市

    1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4105  Solved: 2595[Submit][Sta ...

  9. 1083: [SCOI2005]繁忙的都市

    1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1319  Solved: 878[Submit][Stat ...

随机推荐

  1. PictureBox控件鼠标进入的手形改变和提示

    PictureBox控件载入了图片后,如果要设置其为链接作用的功能,一般需要当鼠标移动到其上时鼠标自动变为手形以提示用户此时可以点击,如果图形无法方便辨识链接的具体功能,最好此时给与一定提示. 1.鼠 ...

  2. php中json_decode返回数组或对象的实例

    1.json_decode() json_decode (PHP 5 >= 5.2.0, PECL json >= 1.2.0) json_decode — 对 JSON 格式的字符串进行 ...

  3. 第六十八篇、OC_按照某一字段对数值进行排序

    代码中是根据"create_time_" 进行排序   ascending:决定的是升序还是降序排序 NSSortDescriptor *sortDescriptor = [[NS ...

  4. UI2_ScrollView&UIPageControl

    // // ViewController.h // UI2_ScrollView&UIPageControl // // Created by zhangxueming on 15/7/10. ...

  5. 关于css的一些小细节---link

    <link rel="stylesheet" href=“a.css” type="text/css"> rel:当前文档与被链接文档间的关系,必须 ...

  6. JQuery Pagination 分页插件 增加了首页尾页以及跳转功能

    JQuery分页插件 挺好用的 但是官方是没有提供首页尾页以及跳转功能 我觉得这个功能可以有,于是就改进了一下 一个js一个css从连接里面下 链接:http://pan.baidu.com/s/1n ...

  7. equals()源代码及释义

    源代码: public boolean equals(Object anObject) {if (this == anObject) { return true;}if (anObject insta ...

  8. Controller层的写法

    项目中的两个Controller层实现类,一个是跳转到jsp页面,一个是以Json形式返回Map键值对. 跳转到jsp页面: package com.controller; import java.i ...

  9. struts2,hibernate4,spring3配置时问题汇总及解决办法

    文章转载于wanglihu的博客,原文链接http://wanglihu.iteye.com/blog/1897718 1.java.lang.NoClassDefFoundError: org/ob ...

  10. C++调用GDAL库读取并输出tif文件,并计算斑块面积输出景观指数:CSD

    部分源码选自GDAL库的官方网址:www.gdal.org,其余的代码为笔者自己编写. // readfile.cpp : 定义控制台应用程序的入口点. // /* part of the codes ...