#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
//your code goes here
int n, m;
cin >> n >> m;
int s, t, l, k;
cin >> s >> t >> l >> k;
s--;
t--;
vector <vector <pair <int, int>>> adj(n);
for(int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
adj[u].push_back({w, v});
adj[v].push_back({w, u});
}
priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> pq = {};
vector <int> dis(n, 1e18);
dis[s] = 0;
pq.push({0, s});
while(!pq.empty()) {
int v1 = pq.top().first;
int v2 = pq.top().second;
pq.pop();
// cout << v2 << endl;
if(dis[v2] != v1) {
continue;
}
for(auto i:adj[v2]) {
int v3 = dis[i.second];
int v4 = i.first;
if((v1+v4) < v3) {
// if(v2 == 0) {
// cout << v1 << " " << v4 << " " << dis[i.second] << " " << i.second << endl;
// }
dis[i.second] = v1+v4;
pq.push({v1+v4, i.second});
}
}
}
vector <int> dis2(n, 1e18);
dis2[t] = 0;
pq.push({0, t});
while(!pq.empty()) {
int v1 = pq.top().first;
int v2 = pq.top().second;
pq.pop();
// cout << v2 << endl;
if(dis2[v2] != v1) {
continue;
}
for(auto i:adj[v2]) {
int v3 = dis2[i.second];
int v4 = i.first;
if((v1+v4) < v3) {
// if(v2 == 0) {
// cout << v1 << " " << v4 << " " << dis[i.second] << " " << i.second << endl;
// }
dis2[i.second] = v1+v4;
pq.push({v1+v4, i.second});
}
}
}
if(dis[t] <= k) {
cout << n*(n-1)/2 << endl;
} else {
int v = k-l;
int total = 0;
sort(dis.begin(), dis.end());
sort(dis2.begin(), dis2.end());
for(int i = 0; i < n; i++) {
int v2 = dis[i];
int v3 = v-v2;
int v4 = upper_bound(dis2.begin(), dis2.end(), v3)-dis2.begin();
total += v4;
}
cout << total << 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... |