zoukankan      html  css  js  c++  java
  • POJ 1797 Heavy Transportation

    SPFA水题。记录一下到这个结点的最大承载能力。因为一个小错误而WA了一晚上,悲催,T_T......

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<vector>
    #include<queue>
    #include<algorithm>
    using namespace std;
    
    const int maxn=1000+10;
    struct Edge{int from,to,w;}e[1000010];
    int dis[maxn],vis[maxn];
    vector<Edge>G[maxn];
    int n,m,tot;
    
    void SPFA()
    {
        queue<int>Q;
        memset(dis,0,sizeof(dis));
        memset(vis,0,sizeof(vis));
        vis[1]=1;
        Q.push(1);
        while(!Q.empty())
        {
            int h=Q.front();Q.pop();vis[h]=0;
            for(int i=0;i<G[h].size();i++)
            {
                Edge &e=G[h][i];
                if(h==1)
                {
                    dis[e.to]=e.w;
                    Q.push(e.to);
                    vis[e.to]=1;
                }
                else
                {
                    if(min(dis[h],e.w)>dis[e.to])
                    {
                        dis[e.to]=min(dis[h],e.w);
                        if(vis[e.to]==0)
                        {
                            Q.push(e.to);
                            vis[e.to]=1;
                        }
                    }
                }
            }
        }
    }
    int main()
    {
        int R,T;
        scanf("%d",&R);
        for(T=1;T<=R;T++)
        {
            scanf("%d%d",&n,&m);
            tot=0;
            for(int i=0;i<=n;i++) G[i].clear();
            while(m--)
            {
                int from,to,w;
                scanf("%d%d%d",&from,&to,&w);
    
                e[tot].from=from;e[tot].to=to;e[tot].w=w;
                G[e[tot].from].push_back(e[tot]);
                tot++;
    
                e[tot].from=to;e[tot].to=from;e[tot].w=w;
                G[e[tot].from].push_back(e[tot]);
                tot++;
            }
            SPFA();
            printf("Scenario #%d:
    ",T);
            printf("%d
    ",dis[n]);
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    redis的数据持久化再讲 关于redisAOF RDB工作原理
    关于redis的持久化数据 RDB,AOF
    关于redis
    docker-compose的使用
    dockerfile定制镜像的使用
    docker常用命令
    关于这两天
    eclipse tomcat找不到或无法加载
    关于jdk代理和cglib代理
    scp 跨机远程拷贝
  • 原文地址:https://www.cnblogs.com/zufezzt/p/4693300.html
Copyright © 2011-2022 走看看