#include <bits/stdc++.h>
#define int long long
#define first first
const int N = 2e5 + 7;
using namespace std;
vector<pair<int, int>> graph[N];
vector<int> dijkstra(int start, vector<int> &dist)
{
set<pair<int, int>> q;
vector<int> vis(dist.size(), 0);
q.insert({0, start});
dist[start] = 0;
int node, weight;
while (q.size())
{
node = q.begin()->second;
q.extract(*q.begin());
if (vis[node])
continue;
vis[node] = 1;
for (auto i : graph[node])
{
if (dist[i.second] > dist[node] + i.first)
{
dist[i.second] = dist[node] + i.first;
q.insert({dist[i.second], i.second});
}
}
}
return dist;
}
void solve()
{
int n, m;
cin >> n >> m;
int s, t, l, k;
cin >> s >> t >> l >> k;
int u, v, w;
for (int i = 0; i < m; i++)
{
cin >> u >> v >> w;
graph[u].push_back({w, v});
graph[v].push_back({w, u});
}
vector<int> sdist(n + 1, 1e18);
vector<int> tdist(n + 1, 1e18);
dijkstra(s, sdist);
dijkstra(t, tdist);
int ans = 0;
if (sdist[t] <= k)
{
cout << n * (n - 1) / 2;
return;
}
sort(sdist.begin() + 1, sdist.end());
sort(tdist.begin() + 1, tdist.end());
for (int i = 1; i <= n; i++)
{
if (sdist[i] == 1e18)
continue;
int kk = --upper_bound(tdist.begin(), tdist.end(), k - l - sdist[i]) - tdist.begin();
ans += max(0ll, kk);
}
cout << ans << endl;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
{
solve();
cout << endl;
}
return 0;
}
# | 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... |