#include <bits/stdc++.h>
using namespace std;
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1LL)
using ll = long long;
const int mxn = 9 + 1e6;
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;
#define int long long
void _27augain(void) {
int n, m;
cin >> n >> m;
int s, t, l, k;
cin >> s >> t >> l >> k;
--s, --t;
vector<vector<array<int, 2>>> adj(n);
for (int i = 1; i <= m; ++i) {
int u, v, w;
cin >> u >> v >> w;
--u, --v;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
auto dijkstra = [&] (int x) -> vector<int> {
vector<int> d(n, lnf);
priority_queue<array<int, 2>> pq;
pq.push({d[x] = 0, x});
while (!pq.empty()) {
int w = -pq.top()[0], u = pq.top()[1];
pq.pop();
if (w > d[u]) {
continue;
}
for (auto &y : adj[u]) {
if (d[y[0]] > d[u] + y[1]) {
d[y[0]] = d[u] + y[1];
pq.push({-d[y[0]], y[0]});
}
}
}
return d;
};
vector<int> dS = dijkstra(s), dT = dijkstra(t);
if (dS[t] <= k) {
cout << n * (n - 1) / 2 << "\n";
return;
}
int res = 0;
vector<int> S;
for (int i = 0; i < n; ++i) {
if (dS[i] ^ lnf) {
S.push_back(dS[i]);
}
}
sort(begin(S), end(S));
vector<int> T;
for (int j = 0; j < n; ++j) {
if (dT[j] ^ lnf) {
T.push_back(dT[j]);
}
}
sort(begin(T), end(T));
for (auto &x : T) {
res += upper_bound(begin(S), end(S), k - l - x) - begin(S);
}
cout << res << "\n";
}
int32_t main(void) {
#define task "_27augain"
cin.tie(0)->sync_with_stdio(0);
for (string iext : {"in", "inp"}) {
if (fopen((task "." + iext).c_str(), "r")) {
freopen((task "." + iext).c_str(), "r", stdin);
freopen(task ".out", "w", stdout);
}
}
int testcase = 1;
// cin >> testcase;
while (testcase--) {
_27augain();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int32_t main()':
Main.cpp:79:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | freopen((task "." + iext).c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:80:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | 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... |