欢迎来到SFWR的博客

P4822 [BJWC2012]冻结

 

 


蜜汁紫题


#include<bits/stdc++.h>
using namespace std;
const int bow=100010;
int n,m,a,b,c,ne,k,head[bow],vist[bow],usd[bow<<2],d[bow];
struct node{int nxt,to,dis;}eg[bow<<2];
void adde(int u,int v,int val){eg[++ne].nxt=head[u];eg[ne].to=v;eg[ne].dis=val;head[u]=ne;}
void spfa(){
    queue<int>q;
    memset(d,0x3f,sizeof(d));
    q.push(1);d[1]=0;vist[1]=1;
    while(!q.empty()){
    int u=q.front();
    q.pop();vist[u]=0;
    for(int i=head[u];i;i=eg[i].nxt)
        if(d[eg[i].to]>d[u]+eg[i].dis){
            d[eg[i].to]=d[u]+eg[i].dis;
            if(!vist[eg[i].to]){vist[eg[i].to]=1;q.push(eg[i].to);}
        }  
    }

}
int main()
{
    cin>>n>>m>>k;
    while(m--)
    {
        cin>>a>>b>>c;
        for(int i=1;i<=k+1;i++)
        {
            adde(a+(i-1)*n,b+i*n,c/2);
            adde(b+(i-1)*n,a+i*n,c/2);
            adde(b+(i-1)*n,a+(i-1)*n,c);
            adde(a+(i-1)*n,b+(i-1)*n,c);
        }
    }
    spfa();
    int ans=0x3f3f3f3f;
    for(int i=1;i<=k+1;i++)ans=min(ans,d[n+(i-1)*n]);
    cout<<ans;
}

 

posted @ 2019-09-02 11:45  SFWR  Views(101)  Comments(0Edit  收藏  举报