uva 11280

题目链接:https://vjudge.net/problem/UVA-11280

 

AC代码

#include 
#include
using namespace std;

vector>maps[103];
int s,e;
int q;
long long dis[130][1000];
struct node{
    int pos;
    int money;
    int tot;
    friend bool operator<(const node &a,const node &b)
    {
        return a.money>b.money;
    }
};

long long spfa()
{
    memset(dis,127,sizeof(dis));
    node n1,n2;
    dis[s][0]=0;
    n1.pos=s;
    n1.money=0;
    n1.tot=0;
    priority_queuepq;
    pq.push(n1);
    while(!pq.empty())
    {
        n1=pq.top();
        pq.pop();
        if(n1.tot>q+1)
            continue;
        if(n1.pos==e)
            return n1.money;
        for(int i=0;in2.money)
            {
                dis[n2.pos][n2.tot]=n2.money;
                pq.push(n2);
            }

        }
    }
    return -1;
}

int main()
{
    int t;
    int ca=1;
    cin>>t;
    while(t--)
    {

        mapshe;
        int n;
        cin>>n;
        for(int i=1;i<=n;++i)
        {
            maps[i].clear();
            string str;
            cin>>str;
            she[str]=i;
            if(str=="Calgary")
                s=i;
            if(str=="Fredericton")
                e=i;
        }
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
        {
            string str1,str2;
            int tt;
            cin>>str1>>str2>>tt;
            maps[she[str1]].push_back(make_pair(she[str2],tt));
        }
        printf("Scenario #%d\n",ca++);
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
        {
            scanf("%d",&q);
            long long ans=spfa();
            if(ans==-1)
                printf("No satisfactory flights\n");
            else
                cout<<"Total cost of flight(s) is $"<

 

你可能感兴趣的:(图论)