73 lines
1.3 KiB
C++
73 lines
1.3 KiB
C++
#include<iostream>
|
|
#include<cstring>
|
|
#include<algorithm>
|
|
#include<cassert>
|
|
#include<string>
|
|
#include<queue>
|
|
using namespace std;
|
|
typedef long long LL;
|
|
const LL inf=(1ll<<60);
|
|
const int maxn=1e5+10;
|
|
const int maxm=5e5+10;
|
|
struct Edge
|
|
{
|
|
int v,w;
|
|
Edge *nxt;
|
|
}buf[maxm*2],*ECnt=buf,*G[maxn];
|
|
inline void AddEdge(int u,int v,int w)
|
|
{
|
|
ECnt->nxt=G[u];
|
|
ECnt->v=v;
|
|
ECnt->w=w;
|
|
G[u]=ECnt++;
|
|
}
|
|
int n,m,s,t,g,q,h[maxn],l[maxn],TMax[maxn];
|
|
LL dist[maxn];
|
|
bool vis[maxn];
|
|
struct QData
|
|
{
|
|
int u; LL UDist;
|
|
};
|
|
inline bool operator<(const QData &A,const QData &B)
|
|
{
|
|
return B.UDist<A.UDist;
|
|
}
|
|
int main()
|
|
{
|
|
#ifdef local
|
|
freopen("pro.in","r",stdin);
|
|
// freopen("pro.out","w",stdout);
|
|
#endif
|
|
scanf("%d%d%d%d%d%d",&n,&m,&s,&t,&g,&q);
|
|
for(int i=1;i<=n;i++)
|
|
{
|
|
scanf("%d%d",&h[i],&l[i]);
|
|
TMax[i]=(l[i]-h[i])/q;
|
|
}
|
|
for(int i=0;i<m;i++)
|
|
{
|
|
int u,v,w; scanf("%d%d%d",&u,&v,&w);
|
|
AddEdge(u,v,w);
|
|
AddEdge(v,u,w);
|
|
}
|
|
for(int i=1;i<=n;i++) dist[i]=inf;
|
|
dist[s]=0;
|
|
priority_queue<QData> Q;
|
|
Q.push((QData){s,0});
|
|
while(Q.size())
|
|
{
|
|
int u=Q.top().u; Q.pop();
|
|
if(vis[u]) continue;
|
|
vis[u]=true;
|
|
if(dist[u]>TMax[u]) continue;
|
|
for(Edge *it=G[u];it;it=it->nxt)
|
|
if(dist[u]+it->w<dist[it->v])
|
|
{
|
|
dist[it->v]=dist[u]+it->w;
|
|
Q.push((QData){it->v,dist[it->v]});
|
|
}
|
|
}
|
|
if(dist[t]<=g) printf("%lld\n",dist[t]);
|
|
else printf("sad\n");
|
|
return 0;
|
|
} |