#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=2e5+5;
ll n, m, s, t, l, k, u, v, w, a[nx], b[nx], ans, vs[nx];
vector<pair<ll, ll>> d[nx];
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
vector<ll> vl;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m>>s>>t>>l>>k;
for (int i=1; i<=m; i++) cin>>u>>v>>w, d[u].push_back({v, w}), d[v].push_back({u, w});
for (int i=1; i<=n; i++) a[i]=b[i]=LLONG_MAX;
a[s]=b[t]=0;
pq.push({0, s});
while (!pq.empty())
{
auto [w, u]=pq.top();
pq.pop();
if (vs[u]) continue;
vs[u]=1;
for (auto [v, nw]:d[u]) if (w+nw<a[v]) a[v]=w+nw, pq.push({w+nw, v});
}
if (a[t]<=k) return cout<<(n*(n-1))/2, 0;
pq.push({0, t});
for (int i=1; i<=n; i++) vs[i]=0;
while (!pq.empty())
{
auto [w, u]=pq.top();
pq.pop();
if (vs[u]) continue;
vs[u]=1;
for (auto [v, nw]:d[u]) if (w+nw<b[v]) b[v]=w+nw, pq.push({w+nw, v});
}
for (int i=1; i<=n; i++) vl.push_back(b[i]);
sort(vl.begin(), vl.end());
for (int i=1; i<=n; i++) if (a[i]!=LLONG_MAX) ans+=(upper_bound(vl.begin(), vl.end(), k-a[i]-l)-vl.begin());
cout<<ans;
}
# | 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... |