#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define yes() cout << "YES\n"
#define no() cout << "NO\n"
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e6;
const int mod1 = 998244353;
const int mod2 = 1e18 + 1;
const int mod3 = 1e9 + 9;
const int mod4 = 333333333;
const int mod5 = 200000;
const int mod6 = 10007;
const int k = 3000;
const int w = 1e5;
const ld EPS = 1e-8;
int LOG = 30;
typedef tree<
int,
null_type,
less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
void solve() {
int n, m, s, t, l, k;
cin >> n >> m >> s >> t >> l >> k;
s--, t--;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
u--, v--;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vector<int> d1(n, inf);
set<pair<int, int>> st;
d1[s] = 0;
st.insert({0, s});
while (st.size()) {
int v = st.begin()->second;
st.erase(st.begin());
for (auto& [u, w] : g[v]) {
if (d1[u] > d1[v] + w) d1[u] = d1[v] + w, st.insert({d1[u], u});
}
}
if (d1[t] <= k) {
cout << n * (n - 1) / 2 << "\n";
return;
}
vector<int> d2(n, inf);
d2[t] = 0;
st.insert({0, t});
while (st.size()) {
int v = st.begin()->second;
st.erase(st.begin());
for (auto& [u, w] : g[v]) {
if (d2[u] > d2[v] + w) d2[u] = d2[v] + w, st.insert({d2[u], u});
}
}
ordered_set st1, st2;
int ans = 0;
// for (int i = 0; i < n; i++) {
// for (int j = i + 1; j < n; j++) {
// if (d1[i] + d2[j] + l <= k) ans++;
// }
// }
for (int i = n - 1; i >= 0; i--) {
if (k - l - d1[i] >= 0) ans += st1.order_of_key(k - l - d1[i] + 1);
st1.insert(d2[i]);
}
for (int i = n - 1; i >= 0; i--) {
if (k - l - d2[i] >= 0) ans += st2.order_of_key(k - l - d2[i] + 1);
st2.insert(d1[i]);
}
// for (int i = 0; i < n; i++) {
// for (int j = i + 1; j < n; j++) {
// if (d2[i] + d1[j] + l <= k) ans++;
// }
// }
cout << ans << "\n";
}
signed main() {
// cout.precision(16);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (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... |