// In honor of El Psy Congroo
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <random>
#include <chrono>
using namespace std;
#pragma GCC optimize("O3")
// variables
using ld = long double;
using ll = long long;
using ull = unsigned long long;
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
// bitwise operations
#define cnt_bit(n) __builtin_popcountll(n)
#define low_bit(n) ((n) & (-(n)))
#define bit(n, i) (((n) >> (i)) & 1)
#define set_bit(n, i) ((n) | (1ll << (i)))
#define reset_bit(n, i) ((n) & ~(1ll << (i)))
#define flip_bit(n, i) ((n) ^ (1ll << (i)))
// math
#define sqr(n) ((n) * (n))
int log2_floor(ull n) {
return n ? __builtin_clzll(1) - __builtin_clzll(n) : -1;
}
// vector
#define len(x) (int) x.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for(auto& el : v) {
is >> el;
}
return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0; i < len(v); i++) {
if (i) os << ' ';
os << v[i];
}
return os;
}
template<class... Args>
auto create(size_t n, Args&&... args) {
if constexpr(sizeof...(args) == 1) {
return vector(n, args...);
}
else {
return vector(n, create(args...));
}
}
template<typename T>
void remove_dups(vector<T>& v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
// random
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
//////solution start//////
const ll INF = 1e18;
void solve() {
int n, m;
cin >> n >> m;
int s, t, l;
ll k;
cin >> s >> t >> l >> k;
s--, t--;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
int v, u, w;
cin >> v >> u >> w;
v--, u--;
g[v].push_back({u, w});
g[u].push_back({v, w});
}
auto dijkstra = [&] (int start) {
vector<ll> dist(n, INF);
vector<ll> val;
dist[start] = 0;
min_heap<pair<ll, int>> pq;
pq.push({dist[start], start});
while (!pq.empty()) {
ll dist_v = pq.top().first;
int v = pq.top().second;
pq.pop();
if (dist[v] != dist_v) continue;
val.push_back(dist[v]);
for (pair<int, int> e : g[v]) {
int u = e.first, w = e.second;
if (dist[u] <= dist[v] + w) continue;
dist[u] = dist[v] + w;
pq.push({dist[u], u});
}
}
return make_pair(dist, val);
};
auto [dist_s, val_s] = dijkstra(s);
auto [dist_t, val_t] = dijkstra(t);
if (dist_s[t] <= k) {
cout << n * 1ll * (n - 1) / 2;
return;
}
ll ans = 0;
int i = 0, j = len(val_t);
while (i < len(val_s)) {
while (j > 0 && val_s[i] + val_t[j - 1] + l > k) {
j--;
}
ans += j;
i++;
}
cout << ans << '\n';
}
//////solution end//////
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
for (int i = 1; i <= tt; i++) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
756 KB |
Output is correct |
7 |
Correct |
49 ms |
22364 KB |
Output is correct |
8 |
Correct |
62 ms |
23780 KB |
Output is correct |
9 |
Correct |
67 ms |
24540 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
31 ms |
15428 KB |
Output is correct |
15 |
Correct |
137 ms |
24780 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
51 ms |
24104 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
30 ms |
15432 KB |
Output is correct |
24 |
Correct |
115 ms |
25008 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
860 KB |
Output is correct |
27 |
Correct |
77 ms |
30872 KB |
Output is correct |
28 |
Correct |
52 ms |
17432 KB |
Output is correct |
29 |
Correct |
44 ms |
18740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
456 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
456 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
632 KB |
Output is correct |
37 |
Correct |
2 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
2 ms |
860 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
1 ms |
600 KB |
Output is correct |
51 |
Correct |
2 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
628 KB |
Output is correct |
53 |
Correct |
2 ms |
860 KB |
Output is correct |
54 |
Correct |
2 ms |
872 KB |
Output is correct |
55 |
Correct |
1 ms |
600 KB |
Output is correct |
56 |
Correct |
2 ms |
612 KB |
Output is correct |
57 |
Correct |
1 ms |
612 KB |
Output is correct |
58 |
Correct |
1 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
756 KB |
Output is correct |
7 |
Correct |
49 ms |
22364 KB |
Output is correct |
8 |
Correct |
62 ms |
23780 KB |
Output is correct |
9 |
Correct |
67 ms |
24540 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
31 ms |
15428 KB |
Output is correct |
15 |
Correct |
137 ms |
24780 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
51 ms |
24104 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
30 ms |
15432 KB |
Output is correct |
24 |
Correct |
115 ms |
25008 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
860 KB |
Output is correct |
27 |
Correct |
77 ms |
30872 KB |
Output is correct |
28 |
Correct |
52 ms |
17432 KB |
Output is correct |
29 |
Correct |
44 ms |
18740 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
344 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
456 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
460 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
604 KB |
Output is correct |
65 |
Correct |
2 ms |
632 KB |
Output is correct |
66 |
Correct |
2 ms |
604 KB |
Output is correct |
67 |
Correct |
1 ms |
604 KB |
Output is correct |
68 |
Correct |
1 ms |
604 KB |
Output is correct |
69 |
Correct |
2 ms |
860 KB |
Output is correct |
70 |
Correct |
1 ms |
604 KB |
Output is correct |
71 |
Correct |
1 ms |
468 KB |
Output is correct |
72 |
Correct |
2 ms |
860 KB |
Output is correct |
73 |
Correct |
1 ms |
604 KB |
Output is correct |
74 |
Correct |
2 ms |
604 KB |
Output is correct |
75 |
Correct |
1 ms |
604 KB |
Output is correct |
76 |
Correct |
1 ms |
604 KB |
Output is correct |
77 |
Correct |
1 ms |
604 KB |
Output is correct |
78 |
Correct |
1 ms |
604 KB |
Output is correct |
79 |
Correct |
1 ms |
600 KB |
Output is correct |
80 |
Correct |
2 ms |
604 KB |
Output is correct |
81 |
Correct |
1 ms |
628 KB |
Output is correct |
82 |
Correct |
2 ms |
860 KB |
Output is correct |
83 |
Correct |
2 ms |
872 KB |
Output is correct |
84 |
Correct |
1 ms |
600 KB |
Output is correct |
85 |
Correct |
2 ms |
612 KB |
Output is correct |
86 |
Correct |
1 ms |
612 KB |
Output is correct |
87 |
Correct |
1 ms |
616 KB |
Output is correct |
88 |
Correct |
81 ms |
23432 KB |
Output is correct |
89 |
Correct |
81 ms |
22808 KB |
Output is correct |
90 |
Correct |
80 ms |
23104 KB |
Output is correct |
91 |
Correct |
38 ms |
9564 KB |
Output is correct |
92 |
Correct |
34 ms |
9568 KB |
Output is correct |
93 |
Correct |
33 ms |
16148 KB |
Output is correct |
94 |
Correct |
34 ms |
16184 KB |
Output is correct |
95 |
Correct |
132 ms |
25520 KB |
Output is correct |
96 |
Correct |
171 ms |
25728 KB |
Output is correct |
97 |
Correct |
107 ms |
25504 KB |
Output is correct |
98 |
Correct |
100 ms |
25748 KB |
Output is correct |
99 |
Correct |
61 ms |
25740 KB |
Output is correct |
100 |
Correct |
64 ms |
25860 KB |
Output is correct |
101 |
Correct |
34 ms |
9500 KB |
Output is correct |
102 |
Correct |
34 ms |
9556 KB |
Output is correct |
103 |
Correct |
35 ms |
16192 KB |
Output is correct |
104 |
Correct |
35 ms |
16296 KB |
Output is correct |
105 |
Correct |
132 ms |
25632 KB |
Output is correct |
106 |
Correct |
151 ms |
25788 KB |
Output is correct |
107 |
Correct |
122 ms |
32220 KB |
Output is correct |
108 |
Correct |
130 ms |
32380 KB |
Output is correct |
109 |
Correct |
66 ms |
18568 KB |
Output is correct |
110 |
Correct |
74 ms |
18492 KB |
Output is correct |
111 |
Correct |
78 ms |
19452 KB |
Output is correct |
112 |
Correct |
81 ms |
19404 KB |
Output is correct |