zoukankan      html  css  js  c++  java
  • 营救

    题目描述

    “咚咚咚……”“查水表!”原来是查水表来了,现在哪里找这么热心上门的查表员啊!小明感动的热泪盈眶,开起了门……

    妈妈下班回家,街坊邻居说小明被一群陌生人强行押上了警车!妈妈丰富的经验告诉她小明被带到了t区,而自己在s区。

    该市有m条大道连接n个区,一条大道将两个区相连接,每个大道有一个拥挤度。小明的妈妈虽然很着急,但是不愿意拥挤的人潮冲乱了她优雅的步伐。所以请你帮她规划一条从s至t的路线,使得经过道路的拥挤度最大值最小。

    输入输出格式

    输入格式:

    第一行四个数字n,m,s,t。

    接下来m行,每行三个数字,分别表示两个区和拥挤度。

    (有可能两个区之间有多条大道相连。)

    输出格式:

    输出题目要求的拥挤度。

    输入输出样例

    输入样例#1:
    3 3 1 3							
    1 2 2
    2 3 1
    1 3 3
    
    输出样例#1:
    2
    

    说明

    数据范围

    30% n<=10

    60% n<=100

    100% n<=10000,m<=2n,拥挤度<=10000

    题目保证1<=s,t<=n且s<>t,保证可以从s区出发到t区。

    样例解释:

    小明的妈妈要从1号点去3号点,最优路线为1->2->3。

    没啥好说的

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cmath>
    #include<vector>
    #include<queue>
    using namespace std;
    int n,m,s,t;
    struct pppp{
        int x;
        int y;
        int c;
    }a[20001];
    int f[10001];
    int find(int x)
    {
        if(f[x]!=x)    f[x]=find(f[x]);
        return f[x];
    }
    void bing(int x,int y)
    {
        int fx=find(x),fy=find(y);
        f[fx]=fy;
    }
    int com(const pppp & x,const pppp & y)
    {
        return x.c<y.c;
    }
    int main()
    {
        scanf("%d%d%d%d",&n,&m,&s,&t);
        int maxn=0;
        for(int i=1,x,y,c;i<=m;i++)
        {
            scanf("%d%d%d",&x,&y,&c);
            a[i].x=x;a[i].y=y;a[i].c=c;
        }
        for(int i=1;i<=n;i++)    f[i]=i;
        sort(a+1,a+m+1,com);
        for(int i=1;i<=m;i++)
        {
            bing(a[i].x ,a[i].y);
            int fx=find(s),fy=find(t);
            if(fx==fy)    
            {    printf("%d",a[i].c);return 0;}        
        }
        
        return 0;
    } 
  • 相关阅读:
    CodeForces 731A Night at the Museum
    nyoj914 Yougth的最大化
    addEventListener或attachEvent都可以用bind代替
    答疑
    js判断是pc还是手机
    js实现xml转json和json转xml
    js实现xml转json
    margin重叠的解决办法
    去除移动端按钮点击时的阴影和rem标签垂直居中
    关于fiddler https 客户端 抓包配置
  • 原文地址:https://www.cnblogs.com/CLGYPYJ/p/6530326.html
Copyright © 2011-2022 走看看