#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
vector<pair<int, int>> adj[200010];
vector<int> vis[2];
void bfs(int s, int t) {
vis[t][s]=0;
pq<pair<int, int>> q;
q.push({0, s});
while (!q.empty()) {
int w = -q.top().F;
s = q.top().S;
q.pop();
if (vis[t][s] < w) continue ;
for (auto i: adj[s]) {
if (w + i.S < vis[t][i.F]) {
vis[t][i.F] = w + i.S;
q.push({-vis[t][i.F], i.F});
}
}
}
}
void solve () {
int n, m, s, t, l, k;
cin >> n >> m >> s >> t >> l >> k;
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
adj[a].pb({b, c});
adj[b].pb({a, c});
}
vis[0] = vis[1] = vector<int>(n+1, 2e18);
bfs(s, 0);
bfs(t, 1);
if (vis[0][t] <= k) {
cout << (n * (n - 1)) / 2 << '\n';
return ;
}
int ans = 0;
sort(all(vis[0]));
sort(rall(vis[1]));
for (int i = 0, r = 1; i < n; i++) {
while (r <= n && vis[0][i] + vis[1][r] + l > k) r++;
ans += n - r + 1;
}
cout << ans << '\n';
}
signed main() {IOS solve(); 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... |