#include <bits/stdc++.h>
#define int long long
#define double long double
#define pii pair <int,int>
#define tiii tuple <int, int, int>
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define ub(a, b) upper_bound(a.begin(), a.end(), b) - a.begin()
#define lb(a, b) lower_bound(a.begin(), a.end(), b) - a.begin()
#define ve vector
#define graph(a, n) vector <int> a[n];
#define wgraph(a, n) vector <pii> a[n];
#define emb emplace_back
#define em emplace
#define ins insert
#define er erase
#define iShowSpeed cin.tie(NULL)->sync_with_stdio(false)
using namespace std;
template <typename T>
using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int mod = 1e9 + 7;
const int inf = 1e18;
const int N = 2e5 + 5;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int n, m, st, en, l, k;
vector <pii> adj[N];
vector <int> dijkstra(int st) {
vector <int> dis(n + 1, inf); dis[st] = 0;
greater_priority_queue <pii> q; q.emplace(0, st);
while (!q.empty()) {
auto [w, u] = q.top(); q.pop();
if (w > dis[u]) continue;
for (auto [ww, v] : adj[u]) {
int www = w + ww;
if (www >= dis[v]) continue;
dis[v] = www;
q.emplace(dis[v], v);
}
}
return dis;
}
int32_t main(){
iShowSpeed;
cin >> n >> m >> st >> en >> l >> k;
for (int i = 0; i < m; i++) {
int u, v, w; cin >> u >> v >> w;
adj[u].emb(w, v);
adj[v].emb(w, u);
}
vector <int> dis1 = dijkstra(st);
if (dis1[en] <= k) return cout << n * (n - 1) / 2, 0;
vector <int> dis2 = dijkstra(en);
sort(all(dis1));
sort(all(dis2));
int ans = 0;
for (auto e : dis1) {
ans += ub(dis2, k - e - l);
}
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... |