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

Description

牛们干草要用完了!贝茜打算去勘查灾情.

有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一个农场.她每走一单位长的路,就要消耗一单位的水.从一个农场走到另一个农场,她就要带上数量上等于路长的水.请帮她确定最小的水箱容量.也就是说,确定某一种方案,使走遍所有农场通过的最长道路的长度最小,必要时她可以走回头路.

Input

第1行输入两个整数N和M;接下来M行,每行输入三个整数,表示一条道路的起点终点和长度.

Output

输出一个整数,表示在路线上最长道路的最小值.

题解:

Djk求从1到每个点,路径上最大边的最小值,取max即可。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
//by zrt
//problem:
using namespace std;
typedef long long LL;
const int inf(0x3f3f3f3f);
const double eps(1e-9);
int H[2005],X[20005],P[20005];
LL E[20005];
LL d[2005];
int tot;
inline void add(int x,int y,LL z){
    P[++tot]=y;X[tot]=H[x];H[x]=tot;E[tot]=z;
}
int n,m;
int x,y;
LL z;
struct N{
    int x;
    LL w;
    N(int a=0,int b=0){
        x=a,w=b;
    }
    friend bool operator < (N a,N b){
        return a.w>b.w;
    }
};
priority_queue<N> q;
bool vis[2005];
int main(){
    #ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    scanf("%d%d",&n,&m);
    memset(d,0x3f,sizeof d);
    for(int i=0;i<m;i++){
        scanf("%d%d%lld",&x,&y,&z);
        add(x,y,z);
        add(y,x,z);
    }
    d[1]=0;
    q.push(N(1,0));
    while(!q.empty()){
        x=q.top().x;q.pop();
        if(vis[x]) continue;
        vis[x]=1;
        for(int i=H[x];i;i=X[i]){
            if(d[P[i]]>max(d[x],E[i])){
                d[P[i]]=max(d[x],E[i]);
                q.push(N(P[i],d[P[i]]));
            }
        }
    }
    LL ans=0;
    for(int i=2;i<=n;i++) ans=max(ans,d[i]);
    printf("%lld\n",ans);
    return 0;
}
时间: 2024-11-12 15:34:47

BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机的相关文章

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

1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 391  Solved: 258[Submit][Status] Description The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms

[Usaco2005 Mar]Out of Hay 干草危机

题目描述 Bessie 计划调查N (2 <= N <= 2,000)个农场的干草情况,它从1号农场出发.农场之间总共有M (1 <= M <= 10,000)条双向道路,所有道路的总长度不超过1,000,000,000.有些农场之间存在着多条道路,所有的农场之间都是连通的. Bessie希望计算出该图中最小生成树中的最长边的长度. 输入格式 两个整数N和M. 接下来M行,每行三个用空格隔开的整数A_i, B_i和L_i,表示A_i和 B_i之间有一条道路长度为L_i. 输出格式

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

...最小生成树裸题,9月最后一天刷水刷水. 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 const int MAXM=10000+50; 6 const int MAXN=2000+50; 7 struct Rec 8 { 9 int ori,des,len; 10 bool operator < (const Rec &x)

BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 shelter 点, 然后对于每个 farm x : S -> cow( x ) = cow( x ) 数量 , shelter( x ) -> T = shelter( x ) 容量 ; 对于每个dist( u , v ) <= m 的 cow( u ) -> shelter( v

BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) differe

bzoj:1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明

Description A crime has been comitted: a load of grain has been taken from the barn by one of FJ's cows. FJ is trying to determine which of his C (1 <= C <= 100) cows is the culprit. Fortunately, a passing satellite took an image of his farm M (1 &l

BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛

Description 约翰的牛们非常害怕淋雨,那会使他们瑟瑟发抖.他们打算安装一个下雨报警器,并且安排了一个撤退计划.他们需要计算最少的让所有牛进入雨棚的时间.    牛们在农场的F(1≤F≤200)个田地上吃草.有P(1≤P≤1500)条双向路连接着这些田地.路很宽,无限量的牛可以通过.田地上有雨棚,雨棚有一定的容量,牛们可以瞬间从这块田地进入这块田地上的雨棚    请计算最少的时间,让每只牛都进入雨棚. Input 第1行:两个整数F和P; 第2到F+1行:第i+l行有两个整数描述第i个田

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

1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 574  Solved: 226[Submit][Status] Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互相作用,每个齿轮都可能驱动着多个齿轮. FJ

bzoj 1680\1740 : [Usaco2005 Mar]Yogurt factory 贪心 双倍经验

1680: [Usaco2005 Mar]Yogurt factory Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk and labor will fluctuate weekly such that it will cost the com