#include <bits/stdc++.h>
using namespace std;
typedef pair<int, long long> pill;
typedef pair<long long, int> plli;
void dijk(vector<pill> adj[], long long dis[], int n, int u) {
int processed[n + 1] = {};
priority_queue<plli, vector<plli>, greater<plli>> pq;
dis[u] = 0;
pq.push({dis[u], u});
while (!pq.empty()) {
int curu = pq.top().second;
int curdis = pq.top().first;
pq.pop();
if (!processed[curu]) {
processed[curu] = 1;
for (pill ptemp: adj[curu]) {
int v = ptemp.second;
int w = ptemp.first;
if (!processed[v]) {
dis[v] = min(dis[v], dis[curu] + w);
pq.push({dis[v], v});
}
}
}
}
// cout << "\n\n";
// cout << "dis[n + 1] :" << "\n";
// for (int i = 1; i <= n; i++) {
// cout << setw(3) << i << " = " << dis[i] << "\n";
// }
// cout << "\n\n";
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int i, j;
int n, m, s, t;
long long l, k, mxdis = 3e9, ans = 0;
cin >> n >> m;
cin >> s >> t >> l >> k;
long long dis[n + 1], dis2[n + 1];
vector<pill> adj[n + 1];
for (i = 0; i <= n; i++) {
dis[i] = mxdis;
dis2[i] = mxdis;
}
for (i = 0; i < m; i++) {
int a, b;
long long c;
cin >> a >> b >> c;
adj[a].push_back({c, b});
adj[b].push_back({c, a});
}
dijk(adj, dis, n, s);
dijk(adj, dis2, n, t);
// for (i = 0; i <= n; i++) {
// cout << dis[i] << "\n";
// }
ans += (l <= k);
for (i = 1; i <= n; i++) {
if ((i != s) && (i != t)) {
ans += (dis[i] + l <= k);
ans += (l + dis2[i] <= k);
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if ((i < j) && (i != s) && (j != t)) {
ans += (dis[i] + l + dis2[j] <= k);
}
}
}
cout << ans;
return 0;
}
/*
7 8
6 7 1 2
1 2 1
1 6 1
2 3 1
2 4 1
3 5 1
3 7 1
4 5 1
5 6 1
*/
# | 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... |