【最小生成树】BZOJ1682[Usaco2005 Mar]-Out of Hay 干草危机
...最小生成树裸题,9月最后一天刷水刷水。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXM=+;
const int MAXN=+;
struct Rec
{
int ori,des,len;
bool operator < (const Rec &x) const
{
return len<x.len;
}
}edge[MAXM];
int par[MAXN],height[MAXN];
int n,m;
int ans; void initset()
{
for (int i=;i<=n;i++)
{
par[i]=i;
height[i]=;
}
} int find(int x)
{
int r=x,temp;
while (par[r]!=r) r=par[r];
while (x!=r)
{
temp=par[x];
par[x]=r;
x=temp;
}
return (r);
} void unionset(int fa,int fb)
{
if (height[fa]>=height[fb])
{
par[fb]=fa;
if (height[fa]==height[fb]) height[fa]++;
}
else
par[fa]=fb;
} void init()
{
scanf("%d%d",&n,&m);
for (int i=;i<m;i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
edge[i].ori=u;
edge[i].des=v;
edge[i].len=w;
}
} void solve()
{
sort(edge,edge+m);
initset();
ans=;
for (int i=;i<m;i++)
{
int fa=find(edge[i].ori);
int fb=find(edge[i].des);
if (fa!=fb)
{
unionset(fa,fb);
ans=max(ans,edge[i].len);
}
}
printf("%d",ans);
} int main()
{
init();
solve();
return ;
}
【最小生成树】BZOJ1682[Usaco2005 Mar]-Out of Hay 干草危机的更多相关文章
- bzoj1682[Usaco2005 Mar]Out of Hay 干草危机*
bzoj1682[Usaco2005 Mar]Out of Hay 干草危机 题意: 给个图,每个节点都和1联通,奶牛要从1到每个节点(可以走回头路),希望经过的最长边最短. 题解: 求最小生成树即可 ...
- 1682: [Usaco2005 Mar]Out of Hay 干草危机
1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 391 Solved: 258[ ...
- 【BZOJ】1682: [Usaco2005 Mar]Out of Hay 干草危机(kruskal)
http://www.lydsy.com/JudgeOnline/problem.php?id=1682 最小生成树裸题.. #include <cstdio> #include < ...
- [Usaco2005 Mar]Out of Hay 干草危机
题目描述 Bessie 计划调查N (2 <= N <= 2,000)个农场的干草情况,它从1号农场出发.农场之间总共有M (1 <= M <= 10,000)条双向道路,所有 ...
- BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机
Description 牛们干草要用完了!贝茜打算去勘查灾情. 有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一 ...
- bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】
二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...
- BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
题目 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec Memory Limit: 64 MB Desc ...
- 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: ...
- BZOJ1680: [Usaco2005 Mar]Yogurt factory
1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 106 Solved: 74[Su ...
随机推荐
- 表格标签(table、行、列、表头)
表格标签 一.<table> <table>代表表格标签. <table></table> 1.width 表示表格宽度,宽度表达方式有像素和百分 ...
- python作业高级FTP(第八周)
作业需求: 1. 用户加密认证 2. 多用户同时登陆 3. 每个用户有自己的家目录且只能访问自己的家目录 4. 对用户进行磁盘配额.不同用户配额可不同 5. 用户可以登陆server后,可切换目录 6 ...
- Wireshark抓包保存文件(图片,视频,音频等)
1.首先选择一个图片的分组 如图的9801 就是JPG 2.对下面的窗口里面选中JPEG File Interchange Format 右键选择 导出分组字节流 3.文件输入XXX.jpg,注意保存 ...
- http 之cookie和session
cookie和session 关于http: 1.http是:无状态.短连接 2.http的请求生命周期:给服务端发送一个请起头,通过域名提取url,通过路由关系匹配,再通过函数+html进行模板加 ...
- (转)什么是CDC类(Communication Device Class)
全文地址:http://justmei.blog.163.com/blog/static/1160998532010321112522467/ 什么是CDC类 (Communication Devic ...
- photoshop 安装问题
问题:“安装程序检测到计算机重新启动操作可能处于挂起状态.建议您退出安装程序,重新启动并重试.” 解决: 1.运行 regedit 打开注册表编辑器. 2.依次展开HKEY_LOCAL_MACHINE ...
- 017 CPU冲高定位方法
1.通过top命令查看cpu占用高的进程ID; 2.通过top -Hp 进程ID 查看该进程下所有线程占用cpu的情况,拿出占用cpu最高的线程ID,换算成十六进制; 3.通过 jstack 进程ID ...
- 数学中的Sin和Cos是什么意思?(转)
数学中的Sin和Cos是什么意思? 作者:admin 分类:生活随笔 发表于 2012年03月21日 16:48 问:数学中的Sin和Cos是什么意思? 答:sin, cos, tan 都是三角函数, ...
- Next Permutation——简单、经典
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- js复制文字
一.原理分析 浏览器提供了 copy 命令 ,可以复制选中的内容 document.execCommand("copy") 如果是输入框,可以通过 select() 方法,选中输入 ...