#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll nx = 2e5+5, inf = 4e18;
ll n,m,s,t,l,k,cnt,pos[nx];
vector<pair<int,ll>> adj[nx]; vector<pair<ll,int>> possibleS, possibleT;
vector<ll> dijkstra(int st)
{
vector<ll> dist(n+1,inf);
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
dist[st] = 0;
pq.push({0,st});
while(!pq.empty())
{
auto [d, u] = pq.top();
pq.pop();
if(d > dist[u]) continue;
for(auto [v,w] : adj[u])
{
if(d+w < dist[v])
{
dist[v] = d+w;
pq.push({dist[v],v});
}
}
}
return dist;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m>>s>>t>>l>>k;
for(int i = 1; i <= n; i++) pos[i] = inf;
for(int i = 1; i <= m; i++)
{
int u,v; ll w; cin>>u>>v>>w;
adj[u].push_back({v,w});
adj[v].push_back({u,w});
}
vector<ll> distS = dijkstra(s);
vector<ll> distT = dijkstra(t);
if(distS[t] <= k)
{
cout<<n*(n-1)/2;
return 0;
}
for(int i = 1; i <= n; i++)
{
if(distS[i]+l <= k) possibleS.push_back({distS[i]+l, i});
if(distT[i] <= k) possibleT.push_back({distT[i], i});
}
sort(possibleT.begin(), possibleT.end());
if(possibleS.empty() || possibleT.empty()) return cout<<0, 0;
for(int i = 0; i < possibleT.size(); i++) pos[possibleT[i].second] = i;
for(int i = 0; i < possibleS.size(); i++)
{
ll cur = possibleS[i].first;
int idx = possibleS[i].second;
if(cur + possibleT[0].first > k) continue;
int l = 0, r = possibleT.size()-1;
while(l<r)
{
int md = (l+r+1)/2;
if(cur+possibleT[md].first <= k) l = md;
else r = md-1;
}
cnt += l + 1;
}
cout<<cnt;
}
| # | 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... |