#include <bits/stdc++.h>
using namespace std;
#define task "main"
#define F first
#define S second
#define ii pair<int, int>
#define il pair<int, long long>
#define li pair<long long, int>
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
const int MAX_N = (int)2e5 + 5;
const long long INF = (long long)1e18 + 1408;
int nNode, nEdge, s, t, l;
long long k;
vector<ii> adj[MAX_N];
long long dist[2][MAX_N];
priority_queue<li, vector<li>, greater<li>> pq;
void dijkstra(int s, long long dist[]) {
FOR(i, 1, nNode) dist[i] = INF;
dist[s] = 0;
pq.push({0, s});
while (!pq.empty()) {
li cur = pq.top();
pq.pop();
int u = cur.S;
if (cur.F > dist[u]) continue;
for (ii e : adj[u]) {
int v = e.F, w = e.S;
if (minimize(dist[v], dist[u] + w))
pq.push({dist[v], v});
}
}
}
void solve() {
cin >> nNode >> nEdge;
cin >> s >> t >> l >> k;
FOR(i, 1, nEdge) {
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
dijkstra(s, dist[0]);
dijkstra(t, dist[1]);
if (dist[0][t] <= k) {
cout << 1LL * nNode * (nNode - 1) / 2;
return;
}
sort(dist[0] + 1, dist[0] + nNode + 1);
sort(dist[1] + 1, dist[1] + nNode + 1);
long long ans = 0;
FOR(i, 1, nNode) {
if (k - l < dist[0][i]) break;
int pos = upper_bound(dist[1] + 1, dist[1] + nNode + 1, k - l - dist[0][i]) - dist[1];
ans += pos - 1;
}
cout << ans;
}
int32_t main() {
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
bool multitest = 0;
int numTest = 1;
if (multitest) cin >> numTest;
while (numTest--) {
solve();
}
return 0;
}
/* Lak lu theo dieu nhac!!!! */
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
93 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |