• luogu P2384 最短路 spfa+数学?


    #include<cstdio>
    #include<queue>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #define mod 9987
    using namespace std;
    const int N=1000005;
    int e[N],ne[N],w[N],idx;
    queue<int> q;
    int h[1005],po[1005][2],vis[1005],tot=0;
    double dis[1005];
    int n,m;
    void add(int a,int b,int c)
    {
        e[idx]=b;
        w[idx]=c;
        ne[idx]=h[a];
        h[a]=idx++;
    }
    int main()
    {
        memset(h,-1,sizeof h);
        cin>>n>>m;
        while(m--)
        {
            int a,b,c;
            cin>>a>>b>>c;
            add(a,b,c);
        }
        memset(dis,127,sizeof(dis));
        dis[1]=0;
        vis[1]=1;
        q.push(1);
        while(q.size())
        {
            int now=q.front();
            q.pop();
            vis[now]=0;
            for(int i=h[now]; ~i; i=ne[i])
            {
                int v=e[i];
                if(dis[v]>dis[now]+log(w[i]))
                {
                    dis[v]=dis[now]+log(w[i]);
                    po[v][0]=now;
                    po[v][1]=w[i];
                    if(!vis[v])
                    {
                        vis[v]=1;
                        q.push(v);
                    }
                }
            }
        }
        int ans=1,pos=n;
        while(pos!=1)
        {
            ans*=po[pos][1];
            ans%=mod;
            pos=po[pos][0];
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    160726 smarty 笔记(2)
    160726 smarty 笔记(1)
    smarty内置函数
    smarty变量调节器
    smarty基础原理
    【Django】:基础
    【十八章】:Web框架
    汇总
    jQuery
    DOM
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/13041094.html
Copyright © 2020-2023  润新知