zoukankan      html  css  js  c++  java
  • 最短路

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <map>
    #include <set>
    #include <cassert>
    using namespace std;
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=n-1;i>=a;i--)
    #define pb push_back
    #define mp make_pair
    #define all(x) (x).begin(),(x).end()
    #define fi first
    #define se second
    #define SZ(x) ((int)(x).size())
    typedef vector<int> VI;
    typedef long long ll;
    typedef pair<int,int> PII;
    const ll mod=1000000007;
    ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    // head
    
    const ll inf=1ll<<60;
    const int N=10100;
    vector<PII> e[N];
    ll dis[N];
    int vis[N];
    set<pair<ll,int> > hs;
    int u[N],v[N],w[N],n,m,L,s,t;
    VI eg;
    void dijkstra(int S,int n) {
        rep(i,0,n) dis[i]=inf,vis[i]=0;
        dis[S]=0;
        rep(i,0,n) hs.insert(mp(dis[i],i));
        rep(i,0,n) {
            int u=hs.begin()->se; hs.erase(hs.begin());
            vis[u]=1;
            rep(j,0,SZ(e[u])) {
                int v=e[u][j].fi;
                if (dis[v]>dis[u]+e[u][j].se) {
                    hs.erase(mp(dis[v],v));
                    dis[v]=dis[u]+e[u][j].se;
                    hs.insert(mp(dis[v],v));
                }
            }
        }
    }
    
    ll ans(ll x) {
        rep(i,0,n) e[i].clear();
        rep(i,0,m) {
            e[u[i]].pb(mp(v[i],w[i]));
            e[v[i]].pb(mp(u[i],w[i]));
        }
        dijkstra(s,n);
        return dis[t];
    }
  • 相关阅读:
    索引
    varnish它是一款高性能的http缓存服务器
    前端性能优化浅谈
    锁机制-SQL Server 数据库
    NET Core中NuGet包
    “干掉” if...else
    混搭.NET技术
    MONO x64 amd_x64
    跨平台移动开发UI语言 -XAML
    使用LinqToExcel读取Excel
  • 原文地址:https://www.cnblogs.com/zxhl/p/5890615.html
Copyright © 2011-2022 走看看