貌似和2763没鸟区别?
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 #define inc(i,l,r) for(i=l;i<=r;i++) 3 #define dec(i,l,r) for(i=l;i>=r;i--) 4 #define inf 1e9 5 #define mem(a) memset(a,0,sizeof(a)) 6 #define ll long long 7 #define NM 50+5 8 using namespace std; 9 int read(){ 10 int x=0,f=1;char ch=getchar(); 11 while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} 12 while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); 13 return f*x; 14 } 15 struct edge{ 16 int t,v; 17 edge *next; 18 }e[2005],*h[NM]; 19 queue<int >q; 20 int d[NM][NM],n,m,p,i,x,y,t,s,ans; 21 bool v[NM]; 22 void add(int x,int y,int v){ 23 e[++s].t=y;e[s].v=v;e[s].next=h[x];h[x]=&e[s]; 24 } 25 int spfa(){ 26 ans=inf; 27 inc(i,0,p){ 28 mem(v); 29 v[1]++;q.push(1);d[i][1]++; 30 while(!q.empty()){ 31 int t=q.front();q.pop();v[t]=false; 32 for(edge *j=h[t];j;j=j->next){ 33 if(!d[i][j->t]||d[i][j->t]>d[i][t]+j->v){ 34 d[i][j->t]=d[i][t]+j->v; 35 if(!v[j->t]){ 36 v[j->t]++;q.push(j->t); 37 } 38 } 39 if(i>0) 40 if(!d[i][j->t]||d[i][j->t]>d[i-1][t]+j->v/2){ 41 d[i][j->t]=d[i-1][t]+j->v/2; 42 if(!v[j->t]){ 43 v[j->t]++;q.push(j->t); 44 } 45 } 46 } 47 } 48 ans=min(ans,d[i][n]-1); 49 } 50 return ans; 51 } 52 int main(){ 53 n=read();m=read();p=read(); 54 inc(i,1,m){ 55 x=read();y=read();t=read(); 56 add(x,y,t);add(y,x,t); 57 } 58 printf("%d",spfa()); 59 return 0; 60 }