1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include<bits/stdc++.h> #define N 100010 #define M 500010 #define INF 99999999999999999 #define ll long long #define mem(a,b) memset(a,b,sizeof(a)) #define fsb(a,b,c) for(ll a=b;a<=c;a++) #define fbs(a,b,c) for(ll a=b;a>=c;a--) using namespace std; ll l[N],n,m,cnt=0,x,y,z,s,t,g,q,head[N],d[N],vis[N]; struct edge{ ll p,nt,l; }a[M*2]; struct node{ ll u,d; }; priority_queue<node>S; int operator <(node a,node b){ return a.d>b.d; } template<typename qw>inline void rll(qw &x){ x=0;qw f=1;char c=getchar(); while(!isdigit(c))f=c=='-'?-1:f,c=getchar(); while(isdigit(c))x=x*10+c-'0',c=getchar(); x*=f; } inline void add(ll x,ll y,ll z){ a[++cnt].p=y;a[cnt].nt=head[x];head[x]=cnt;a[cnt].l=z; } int main(){ rll(n);rll(m);rll(s);rll(t);rll(g);rll(q); fsb(i,1,n){ rll(x);rll(y);l[i]=(i==s||i==t)?(INF):((q==0?INF:(y-x)/q)); } mem(head,255); fsb(i,1,m){ rll(x);rll(y);rll(z);add(x,y,z);add(y,x,z); } mem(vis,0);mem(d,60);d[s]=0;S.push((node){s,0}); while(!S.empty()){ ll u=S.top().u;S.pop(); if(vis[u])continue; vis[u]=1; if(d[u]>g)break; for(ll t=head[u];t!=-1;t=a[t].nt){ ll v=a[t].p; if(vis[v]||d[u]+a[t].l>d[v]||d[u]+a[t].l>l[v])continue; d[v]=d[u]+a[t].l;S.push((node){v,d[v]}); } } if(d[t]>g)puts("wtnap wa kotori no oyatsu desu!");else printf("%lld\n",d[t]); return 0; }
|