#include <bits/stdc++.h>
#define pi pair<int, int>
#define int long long
#define ff first
#define ss second
const int N = 2e5 + 7;
using namespace std;
vector<pi> graph[N];
vector<int> dijkstra(int start, int N)
{
vector<int> dist(N, 1e18);
priority_queue<pi, vector<pi>, greater<pi>> q;
q.push({0, start});
dist[start] = 0;
int node, weight;
while (q.size())
{
node = q.top().ss;
q.pop();
for (auto i : graph[node])
{
if (dist[i.ss] > dist[node] + i.ff)
{
dist[i.ss] = dist[node] + i.ff;
q.push({dist[i.ss], i.ss});
}
}
}
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 = dijkstra(s, n + 1);
vector<int> tdist = dijkstra(t, n + 1);
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++)
// {
// cout << sdist[i] << " ";
// }
// cout << endl;
// for (int i = 1; i <= n; i++)
// {
// cout << tdist[i] << " ";
// }
// cout << endl;
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();
// cout << " for " << sdist[i] << " we have " << kk << endl;
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... |