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:\n",T);
        printf("%d\n",dis[n]);
        printf("\n");
    }
    return 0;
}
时间: 2024-08-27 02:50:44

POJ 1797 Heavy Transportation的相关文章

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 【最大生成树,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

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

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(二分+并查集/kruskal)

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