[JLOI2011]飞行路线

题目链接

算法:

        我们设dis[i][j]表示从t到i的路,搭乘了j次飞机的最小费用,接着我们利用SPFA进行状态的转移即可,

        答案即为max{dis[t][i](0<=i<=k)}。(考虑到k可能大于路径的条数。)

 

Code:

#include
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template void read(T &num){
    char c=getchar();num=0;T f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
    num*=f;
}
template void qwq(T x){
    if(x>9)qwq(x/10);
    putchar(x%10+'0');
}
template void write(T x){
    if(x<0){x=-x;putchar('-');}
    qwq(x);putchar('\n');
}
template void chkmin(T &x,T y){x=x > >v;
int dis[10010][15];bool in[10010][15];
inline void SPFA(){
    rep(i,1,n){
        rep(j,0,k){dis[i][j]=INT_MAX;}
    }
    v.push(make_pair(0,make_pair(s,0)));in[s][0]=1;dis[s][0]=0;
    while(!v.empty()){
        int nop1=v.top().second.first;int nop2=v.top().second.second;
        in[nop1][nop2]=0;v.pop();
        for(int i=head[nop1];i;i=edge[i].nxt){
            int temp=edge[i].vertice;
            if(dis[nop1][nop2]+edge[i].w

 

你可能感兴趣的:(最短路)