# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1268610 | duyanhloveav | Construction Project 2 (JOI24_ho_t2) | C++20 | 7 ms | 584 KiB |
#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);
int res = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (dS[i] + dT[j] <= k - l) {
++res;
}
}
}
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;
}
Compilation message (stderr)
# | 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... |