HDU 2145wa

还是WA了,这个究竟是为神魔?

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#define INF 1e9
using namespace std;
const int maxn = 300+10;

struct Edge
{
    int from,to,dist;
    Edge(int f,int t,int d):from(f),to(t),dist(d){}
};

struct BellmanFord
{
    int n,m;
    vector<Edge> edges;
    vector<int> G[maxn];
    bool inq[maxn];
    int d[maxn];

    void init(int n)
    {
        this->n = n;
        for(int i=1;i<=n;i++) G[i].clear();
        edges.clear();
    }

    void AddEdge(int from,int to,int dist)
    {
        edges.push_back(Edge(from,to,dist));
        m = edges.size();
        G[from].push_back(m-1);
    }

    void spfa(int s)
    {
        memset(inq,0,sizeof(inq));
        queue<int> Q;
        for(int i=1;i<=n;i++) d[i]= i==s?0:INF;
        Q.push(s);

        while(!Q.empty())
        {
            int u=Q.front(); Q.pop();
            inq[u]=false;
            for(int i=0;i<G[u].size();i++)
            {
                Edge &e=edges[G[u][i]];
                if(d[e.to] > d[u]+e.dist)
                {
                    d[e.to] = d[u]+e.dist;
                    if(!inq[e.to])
                    {
                        inq[e.to]=true;
                        Q.push(e.to);
                    }
                }
            }
        }
    }
}BF;


int n,m,k;

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    BF.init(n);
    while(k--){
        int u,v,cost;
        scanf("%d%d%d",&u,&v,&cost);
        //BF.AddEdge(n,m,cost);
        BF.AddEdge(v,u,cost);
    }
    int st;
    scanf("%d",&st);
    int ed[maxn],speed[maxn];
    for(int i=1;i<=m;i++){
        int tmp;
        scanf("%d",&tmp);
        ed[i]=tmp;
    }
    for(int i=1;i<=m;i++){
        int tmp;
        scanf("%d",&tmp);
        speed[i]=tmp;
    }
    BF.spfa(st);
    int flag=0;
    double tm=INF;//=(double)(BF.d[ed[1]]/speed[1]);
    int judge=0;
   // if(m==1&&BF.d[ed[1]]!=INF){printf("1\n");return 0;}
    for(int i=1;i<=m;i++)if(BF.d[ed[i]]!=INF)
    {
        if((double)BF.d[ed[i]]/speed[i]<tm||((double)BF.d[ed[i]]/speed[i]==tm&&speed[i]>=speed[flag])){
            flag=i;
            tm=(double)BF.d[ed[i]]/speed[i];
        }
    }
    for(int i=1;i<=m;i++){
        if(BF.d[i]==INF)judge++;
    }   
    if(!flag){printf("No one\n");return 0;}

    printf("%d\n",flag);
    return 0;
}






















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值