bzoj1682[Usaco2005 Mar]Out of Hay 干草危机

题意:

给个图,每个节点都和1联通,奶牛要从1到每个节点(可以走回头路),希望经过的最长边最短。

题解:

求最小生成树即可。

代码:

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define inc(i,j,k) for(int i=j;i<=k;i++)
#define maxn 100010
#define ll long long
using namespace std; inline int read(){
char ch=getchar(); int f=,x=;
while(ch<''||ch>''){if(ch=='-')f=-; ch=getchar();}
while(ch>=''&&ch<='')x=x*+ch-'',ch=getchar();
return f*x;
}
int n,m,ans,fa[maxn],tot; struct e{int f,t,w;}es[maxn]; bool cmp(e a,e b){return a.w<b.w;}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
int main(){
n=read(); m=read(); inc(i,,m){int x=read(),y=read(),z=read(); es[i]=(e){x,y,z};} sort(es+,es++m,cmp);
inc(i,,n)fa[i]=i;
inc(i,,m){
int x=find(es[i].f),y=find(es[i].t);
if(x!=y){fa[x]=y; tot++; ans=max(ans,es[i].w); if(tot==n-)break;}
}
printf("%d",ans); return ;
}

20160920

bzoj1682[Usaco2005 Mar]Out of Hay 干草危机*的更多相关文章

  1. 【最小生成树】BZOJ1682[Usaco2005 Mar]-Out of Hay 干草危机

    ...最小生成树裸题,9月最后一天刷水刷水. #include<iostream> #include<cstdio> #include<algorithm> usi ...

  2. 1682: [Usaco2005 Mar]Out of Hay 干草危机

    1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 391  Solved: 258[ ...

  3. 【BZOJ】1682: [Usaco2005 Mar]Out of Hay 干草危机(kruskal)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1682 最小生成树裸题.. #include <cstdio> #include < ...

  4. BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机

    Description 牛们干草要用完了!贝茜打算去勘查灾情. 有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一 ...

  5. [Usaco2005 Mar]Out of Hay 干草危机

    题目描述 Bessie 计划调查N (2 <= N <= 2,000)个农场的干草情况,它从1号农场出发.农场之间总共有M (1 <= M <= 10,000)条双向道路,所有 ...

  6. bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】

    二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...

  7. BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

    题目 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MB Desc ...

  8. 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

    1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit:  ...

  9. BZOJ1680: [Usaco2005 Mar]Yogurt factory

    1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 106  Solved: 74[Su ...

随机推荐

  1. mysql字符串类型(set类型)

    集合 set  不定想项选 类似于 enum枚举,在定义时,也需要指定其已有值! 与字符串相比,优势是: 1, 也是采用 整数进行管理的!采用位运算,从第一位开始为1,逐一x2! 2, 每个集合类型8 ...

  2. 01---eclipse使用

    一.eclipse快捷键 1.alt+? 或 alt+/:自动补全代码或者提示代码,可用于main函数(main).输出函数(syso)等 2.ctrl+1:错误提示 3.ctrl+/:自动注释当前行 ...

  3. mysql常用基础指令大全

    mysql指令 启动 net start mysql 退出mysql quit 登录 mysql -uroot -p 逻辑非 not ! 逻辑与 and && 或者 or || 逻辑异 ...

  4. 4a-c++ primer宽字符wchar_t显示设置与输出代码示例

    .. #include <iostream> #include <windows.h> #include <locale> //#include<wchar. ...

  5. Docker(一)Docker概述

    Docker概述 概述 Docker是供开发人员和系统管理员 使用容器构建,运行和共享应用程序的平台.使用容器来部署应用程序称为容器化.容器不是新的,但用于轻松部署应用程序的容器却是新的. 容器化越来 ...

  6. 使用word2016发有代码高亮的博客

    复制使用notepad++,eclipse这类有高亮的编辑器编写的代码到word中是默认有高亮的. 测试有没有代码高亮(eclipse代码): package p_day1; public class ...

  7. eclipse使用git提交代码

    准备工作: 目的:eclipse使用git提交本地项目,提交至远程github上 eclipse版本:eclipse4.5  64位 jdk版本:jdk-1.7 64位 项目类型:maven web项 ...

  8. 【MonogDB帮助类】

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using MongoDB; ...

  9. 前端进阶笔记之核心基础知识---那些HTML标签你熟悉吗?

    目录 1.交互实现 1.1 meta标签:自动刷新/跳转 1.2 title标签:消息提醒 2.性能优化 2.1 script标签:调整加载顺序提升渲染速度 2.2 link标签:通过预处理提升渲染速 ...

  10. React-Native WebView使用本地js,css渲染html

    前言 最近在使用React-Native开发一个App,遇见一个问题,Webview组件根据url来加载页面,但是这样导致的一个问题页面加载的时间有点长,我想优化一下,因为页面只要是一些内容展示,我想 ...