#include <bits/stdc++.h>
using namespace std;
#define bismillah ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define endl '\n'
ll inf = 1e18;
ll N, M, S, T, L, K;
vector<pll> adj[200005];
void dijkstra(int source, vector<ll>& dist) {
vector<ll> vist(N+1);
for (int i = 1; i <= N; i++) {
dist[i] = inf;
vist[i] = false;
}
dist[source] = 0;
priority_queue<pll, vector<pll>, greater<pll>> pq;
pq.push({0, source});
while (!pq.empty()) {
ll top = pq.top().se;
pq.pop();
if (vist[top]) continue;
vist[top] = true;
for (auto [nei, wei] : adj[top]) {
if (dist[nei] > dist[top] + wei) {
dist[nei] = dist[top] + wei;
pq.push({dist[nei], nei});
}
}
}
}
void solve() {
cin >> N >> M >> S >> T >> L >> K;
for (int i = 0; i < M; i++) {
ll a, b, c;
cin >> a >> b >> c;
adj[a].pb({b, c});
adj[b].pb({a, c});
}
vector<ll> dariS(N+1), dariT(N+1);
dijkstra(S, dariS);
dijkstra(T, dariT);
if (dariS[T] <= K) {
cout << N*(N-1)/2 << endl;
return;
}
vector<pll> no;
for (int i = 1; i <= N; i++) {
no.pb({dariT[i], i});
}
sort(no.begin(), no.end(), greater<pll>());
ll ans = 0;
for (int i = 0; i < N-1; i++) {
int l = i+1;
int r = N-1;
int mid;
int lb = -1;
while (l <= r) {
mid = (l + r)/2;
if (dariS[i] + L + dariT[mid] <= K) {
lb = mid;
r = mid-1;
} else l = mid+1;
}
if (lb != -1) {
ans += (N-lb);
}
}
cout << ans << endl;
}
int main() {
bismillah;
int T = 1;
// cin >> T;
for (;T--;) solve();
}
| # | 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... |