![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e18; const int M = 1e5+7; int n,m,cnt,head[M],flag[M]; struct edge { int v,nex;ll w; }e[M*5]; void init(){ cnt=0;memset(head,-1,sizeof(head));memset(flag,0,sizeof(flag)); } void add(int u,int v,ll w){ e[++cnt].v=v;e[cnt].w=w;e[cnt].nex=head[u]; head[u]=cnt; } struct node { int index,level;ll dis; }d[M][2]; void dijkstra(int s,int t){ for(int i=1;i<=n;i++) for(int j=0;j<=1;j++) d[i][j].dis=inf,d[i][j].index=i,d[i][j].level=j; priority_queue<node> q;d[s][0].dis=0;q.push(d[s][0]); while(!q.empty()){ int u=q.top().index,lv=q.top().level; if(flag[u]) continue; flag[u]=1; for(int i=head[u];~i;i=e[i].nex){ int v=e[i].v;ll w=e[i].w; if(d[v][lv].dis>d[u][lv].dis+w){ d[v][lv].dis=d[u][lv].dis+w; q.push(d[v][lv]); } if(lv==0&&d[v][lv+1].dis>d[u][lv].dis+w/2){ d[v][lv+1].dis=d[u][lv].dis+w/2; q.push(d[v][lv+1]); } } } ll ans=min(d[t][0].dis,d[t][1].dis); printf("%lld\n",ans); } int main(){ return 0; }