Heavy Transportation POJ - 1797

#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<cstring>
#include<cstring>
#include<cstdio>
#include<math.h>
using namespace std;
const int N=1e6+100;
int h[N],w[N],ne[N],e[N],idx;
bool st[N];
int dist[N];
const int INF=0x3f3f3f3f;
void add(int a,int b,int c)
{
    e[idx]=b;
    w[idx]=c;
    ne[idx]=h[a];
    h[a]=idx++;
}
void spfa()
{
    queue<int>q;
    memset(dist,0,sizeof dist);
    memset(st,0,sizeof st);
    st[1]=1;
    q.push(1);
    dist[1]=INF;
    while(q.size())
    {
        int t=q.front();
        q.pop();
        st[t]=false;
        for(int i=h[t];~i;i=ne[i])
        {
            int j=e[i];
            if(dist[j]<min(dist[t],w[i]))
            {
                dist[j]=min(dist[t],w[i]);
                if(!st[j])
                {
                    q.push(j);
                    st[j]=1;
                }
            }
        }
    }
}
int main()
{
    int num=0;
    int t;
    scanf("%d",&t);

    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        memset(h,-1,sizeof h);
        for(int i=1;i<=m;i++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            add(a,b,c);
            add(b,a,c);
        }
        spfa();
        num++;
        printf("Scenario #%d:\n",num);
        printf("%d\n\n",dist[n]);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12239868.html

时间: 2024-10-26 18:43:13

Heavy Transportation POJ - 1797的相关文章

Heavy Transportation POJ 1797 最短路变形

Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你求从编号为1的城市到编号为n的城市的路线中,最大能经过多重的车. 解题思路 这个题可以使用最短路的思路,不过转移方程变了\(dis[j]=max(dis[j], min(dis[u], e[u][j]))\).这里dis[j]表示从标号为1的点到达编号为j的点的路径中,最小的承重能力,就像短板效应样

C - Heavy Transportation POJ - 1797

BackgroundHugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place w

POJ 1797 Heavy Transportation (Dijkstra变形)

F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand busines

POJ 1797 Heavy Transportation SPFA变形

原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 24576   Accepted: 6510 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand

POJ 1797 Heavy Transportation (最短路变形)

Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 20364   Accepted: 5401 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man

poj 1797 Heavy Transportation(最大生成树)

poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has

POJ 1797 Heavy Transportation 【最大生成树,Prime】

Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 29765   Accepted: 7944 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man

POJ 1797 Heavy Transportation【Dijkstra最短路变形】

Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 29682   Accepted: 7919 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man

POJ 1797 Heavy Transportation (Dijkstra)

题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant