跳到正文

剪贴板

剪贴板 lbu4o5gp

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
    ll x=0;char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x;
}
const int N=2e5+10,M=N<<1;
struct ok{
    int x;ll y;
    bool operator <(const ok &A) const{return y>A.y;}
};
int n,m,S,T,L;
int first[N],to[M],nxt[M],lth[M],cnt;
bool vis[N];
ll K,ans,a[N],dis[N][2];
priority_queue<ok>q;
inline void inc(int x,int y,int l) {nxt[++cnt]=first[x],to[cnt]=y,first[x]=cnt,lth[cnt]=l;}
void Dij(int fi,bool p)
{
    for(int i=1;i<=n;i++)
        vis[i]=0,dis[i][p]=1e18;
    dis[fi][p]=0,q.push((ok){fi,0});
    while(!q.empty())
    {
        int x=q.top().x;
        q.pop();
        if(vis[x]) continue;
        vis[x]=1;
        for(int i=first[x],v;i;i=nxt[i])
            if(dis[v=to[i]][p]>dis[x][p]+lth[i])
                dis[v][p]=dis[x][p]+lth[i],q.push((ok){v,dis[v][p]});
    }
}
int main()
{
    n=read(),m=read(),S=read(),T=read(),L=read(),K=read();
    int u,v,w;
    while(m--)
        u=read(),v=read(),w=read(),inc(u,v,w),inc(v,u,w);
    Dij(S,0),Dij(T,1);
    if(dis[T][0]<=K) return printf("%lld\n",1ll*n*(n-1)/2),0;
    for(int i=1;i<=n;i++) a[i]=dis[i][1];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        ans+=upper_bound(a+1,a+n+1,K-L-dis[i][0])-a-1;
    printf("%lld\n",ans);
    return 0;
}