priority_queue>>q; ll@n,@k,@m,@p; int u[m],v[]; rd((u--,v--)(m)); graph g; g.setEdge(n,m,u,v); ll@s[n],r[n]{},t[n]{}; rep(k){ ll@x--; t[x]=1; rep(j,g.es[x]){ ll a=g.edge[x][j]; q.push({-s[x],{x,a}}); } } while(!q.empty()){ auto b=q.top(); q.pop(); if(t[b.second.first]==1){ ll x=b.second.second; if(!t[x]){ t[x]=1; r[x]=-b.first; rep(j,g.es[x]){ ll a=g.edge[x][j]; q.push({b.first-s[x],{x,a}}); } }else if(r[x]>-b.first-p){ t[x]=2; } } } wt(sum[ll][i,0,n](t[i]==2));