(简单) POJ 1797 Heavy Transportation,Dijkstra。

  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
steel crane to the place where it is needed on which all streets can
carry the weight.

Fortunately he already has a plan of the city with all
streets and bridges and all the allowed weights.Unfortunately he has no
idea how to find the the maximum weight capacity in order to tell his
customer how heavy the crane may become. But you surely know.

Problem
  You are given the plan of the city, described
by the streets (with weight limits) between the crossings, which are
numbered from 1 to n. Your task is to find the maximum weight that can
be transported from crossing 1 (Hugo‘s place) to crossing n (the
customer‘s place). You may assume that there is at least one path. All
streets can be travelled in both directions.

  题目就是求最大路。。。

代码如下:

#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>

#define min(a,b) (a<b ? a:b)

using namespace std;

const int INF=10e8;
const int MaxN=1010;

struct Node
{
    int v,val;

    Node(int _v=0,int _val=0):v(_v),val(_val) {}
    bool operator < (const Node &a) const
    {
        return val<a.val;
    }
};

struct Edge
{
    int v,cost;

    Edge(int _v=0,int _cost=0):v(_v),cost(_cost) {}
};

vector <Edge> E[MaxN];

void Dijkstra(int lowcost[],int n,int start)
{
    priority_queue <Node> que;
    Node qtemp;
    int len;
    int u,v,cost;

    for(int i=1;i<=n;++i)
    {
        lowcost[i]=0;
    }
    lowcost[start]=INF;

    que.push(Node(start,INF));

    while(!que.empty())
    {
        qtemp=que.top();
        que.pop();

        u=qtemp.v;

        len=E[u].size();

        for(int i=0;i<len;++i)
        {
            v=E[u][i].v;
            cost=E[u][i].cost;

            if(min(cost,lowcost[u])>lowcost[v])
            {
                lowcost[v]=min(cost,lowcost[u]);
                que.push(Node(v,lowcost[v]));
            }
        }
    }
}

inline void addEdge(int u,int v,int c)
{
    E[u].push_back(Edge(v,c));
}

int ans[MaxN];

int main()
{
//    ios::sync_with_stdio(false);

    int N,M;
    int a,b,c;
    int T;

    scanf("%d",&T);

    for(int cas=1;cas<=T;++cas)
    {
        scanf("%d %d",&N,&M);

        for(int i=1;i<=N;++i)
            E[i].clear();

        for(int i=1;i<=M;++i)
        {
            scanf("%d %d %d",&a,&b,&c);

            addEdge(a,b,c);
            addEdge(b,a,c);
        }

        Dijkstra(ans,N,1);

        printf("Scenario #%d:\n",cas);
        printf("%d\n\n",ans[N]);
    }

    return 0;
}

时间: 2024-08-01 22:47:47

(简单) POJ 1797 Heavy Transportation,Dijkstra。的相关文章

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

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 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 (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【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 变式】

Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 23914   Accepted: 6355 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 【最大生成树,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(最大生成树/最短路变形)

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