• P4568 [JLOI2011]飞行路线 分层图最短路


    思路:裸的分层图最短路

    提交:1次

    题解:

    如思路

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<queue>
    #define R register int
    using namespace std;
    #define ull unsigned long long
    #define ll long long
    #define pause (for(R i=1;i<=10000000000;++i))
    #define IN freopen("NOIPAK++.in","r",stdin)
    #define OUT freopen("out.out","w",stdout)
    namespace Fread {
        static char B[1<<15],*S=B,*D=B;
    #ifndef JACK
        #define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
    #endif
        inline int g() {
            R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
            if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
        } inline bool isempty(const char& ch) {return ch!=EOF&&(ch<=36||ch>=127);}
        inline void gs(char* s) {
            register char ch; while(isempty(ch=getchar())); if(ch==EOF) return ;
            do *s++=ch; while(!isempty(ch=getchar()));
        }
    }using Fread::g; using Fread::gs;
    const int N=10010,M=50010;
    #define fr first
    #define sc second
    #define mp make_pair
    #define pii pair<int,int> 
    int n,m,k,s,t,cnt,ans=0x3f3f3f3f;
    int vr[M<<1],nxt[M<<1],fir[N],w[M<<1],d[N][15]; bool vis[N][15];
    inline void add(int u,int v,int ww) {vr[++cnt]=v,nxt[cnt]=fir[u],w[cnt]=ww,fir[u]=cnt; }
    inline void dijk() { priority_queue<pair<int,pii > > q;
        memset(d,0x3f,sizeof(d)); d[s][0]=0; q.push(mp(0,mp(s,0)));
        while(q.size()) { register pii tmp=q.top().sc; q.pop();
            R u=tmp.fr,t=tmp.sc; if(vis[u][t]) continue;
            for(R i=fir[u];i;i=nxt[i]) { R v=vr[i];
                if(d[v][t]>d[u][t]+w[i]) d[v][t]=d[u][t]+w[i],q.push(mp(-d[v][t],mp(v,t)));
                if(t<k&&d[v][t+1]>d[u][t]) d[v][t+1]=d[u][t],q.push(mp(-d[v][t+1],mp(v,t+1)));
            }
        }
    }
    signed main() {
    #ifdef JACK
    #endif
        n=g(),m=g(),k=g(),s=g(),t=g(); for(R i=1,u,v,w;i<=m;++i) u=g(),v=g(),w=g(),add(u,v,w),add(v,u,w);
        dijk(); for(R i=0;i<=k;++i) ans=min(ans,d[t][i]); printf("%d
    ",ans);
    }
    

    2019.07.22

  • 相关阅读:
    5.数组的使用,最值和反转
    4.下标越界及小结
    3.数组的三种初始化及简单内存分析
    html5版 音乐播放器
    百度网盘搜索
    HTML5扩展之微数据与丰富网页摘要
    Java 学习文章汇总
    业余草
    Catalan数
    Luogu P3004 [USACO10DEC]宝箱Treasure Chest
  • 原文地址:https://www.cnblogs.com/Jackpei/p/11226257.html
Copyright © 2020-2023  润新知