#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
const ll N=2e5+100;
ll dist[N],tmp=0;
vector<pair<ll,ll>> ma[N];
ll n,m;
void compute(ll s)
{
    for(ll i=0;i<=n;i++)
    {
        dist[i]=1e18;
    }
    dist[s]=0;
    priority_queue<pair<ll,ll>> pq;
    pq.push({0,s});
    while(pq.size())
    {
        auto it=pq.top();
        pq.pop();
        ll x=it.second,dt=it.first;
        if(dist[x]!=dt)continue;
        for(auto y:ma[it.second])
        {
            if(dist[y.first]>(dt+y.second))
            {
                dist[y.first]=dt+y.second;
                pq.push({dt+y.second,y.first});
            }
        }
    }
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
void solve()
{
    tmp=0;
    cin>>n>>m;
    ll s,t,l,k;
    cin>>s>>t>>l>>k;
    for(ll i=0;i<m;i++)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        ma[a].pb({b,c});
        ma[b].pb({a,c});
    }
    compute(s);
    vector<ll> cur,dist1(n+2);
    for(ll i=1;i<=n;i++)
    {
        cur.pb(dist[i]);
        dist1[i]=dist[i];
    }
    sort(begin(cur),end(cur));
    compute(t);
    ll ans=0,c0=0,c1=0;;
    vector<pair<ll,ll>> val;
    for(ll i=1;i<=n;i++)
    {
        // dist(s,i) + dist(j,t) + l <= k
        // OR
        // dist(s,i)+dist(i,t) <=k
        // OR
        // dist(s,j)+dist(j,t)<=k
        if(dist1[i]+dist[i] <=k )
        {
            ans+=c0+c1;
            c1++;
        }
        else
        {
            ans+=c1;
            c0++;
            val.pb({dist1[i],i});
        }
        // We did dist(s,i)+dist(i,t) <=k or dist(s,j)+dist(j,t) <=k  unordered (i,j)=(j,i)
        // We need to add dist(s,i)+dist(i,t) > k and dist(s,j)+dist(j,t)>k and dist(s,i)+dist(j,t)+l<=k 
        // p 
    }
    sort(begin(val),end(val));
    ordered_set tp;
    for(auto [kp,i]:val)
    {
        //try i to be with s 
        // dist(j,t) <= k-l-kp
        ans+=tp.order_of_key(k-l-kp);
        // i with t
        // dist(s,j) <=k-l - dist(i,t)
        ans+=upper_bound(begin(val),end(val),make_pair(k-l-dist[i],n+1))-begin(val);
        tp.insert(dist[i]);
    }
    // ans/=2; 
    cout<<ans<<endl;
    // sort(dist);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |