#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[200005];
long long d[2][200005];
void dij(int i, int s) {
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
q.emplace(0, s);
d[i][s] = 0;
while (q.size()) {
int u = q.top().second;
long long dl = q.top().first;
q.pop();
if (dl > d[i][u]) {
continue;
}
for (pair<int, int> p: g[u]) {
int v = p.first, w = p.second;
if (d[i][v] > d[i][u] + w) {
d[i][v] = d[i][u] + w;
q.emplace(d[i][v], v);
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, s, t, l;
long long k;
cin >> n >> m >> s >> t >> l >> k;
for (int i = 1; i <= m; ++i) {
int u, v, w;
cin >> u >> v >> w;
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
memset(d, 0x3f3f3f3f, sizeof d);
dij(0, s);
dij(1, t);
if (d[0][t] <= k) {
cout << 1ll * n * (n - 1) / 2 << '\n';
return 0;
}
vector<long long> v;
for (int i = 1; i <= n; ++i) {
v.emplace_back(d[1][i]);
}
sort(v.begin(), v.end());
long long ans = 0;
for (int i = 1; i <= n; ++i) {
int j = upper_bound(v.begin(), v.end(), k - l - d[0][i]) - v.begin();
if (d[1][i] <= k - l - d[0][i]) {
j--;
}
ans += j;
}
cout << ans << '\n';
}
/*
18 21
4 8 678730772 3000000062
5 13 805281073
8 17 80983648
3 8 996533440
10 16 514277428
2 5 57914340
6 11 966149890
8 12 532734310
2 9 188599710
2 3 966306014
12 16 656457780
16 18 662633078
1 15 698078877
2 8 665665772
2 6 652261981
14 15 712798281
7 13 571169114
13 14 860543313
6 7 454251187
9 14 293590683
6 14 959532841
3 11 591245645
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
3 ms |
8024 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8284 KB |
Output is correct |
7 |
Correct |
58 ms |
17936 KB |
Output is correct |
8 |
Correct |
68 ms |
18168 KB |
Output is correct |
9 |
Correct |
64 ms |
18264 KB |
Output is correct |
10 |
Correct |
4 ms |
8028 KB |
Output is correct |
11 |
Correct |
4 ms |
8024 KB |
Output is correct |
12 |
Correct |
4 ms |
8284 KB |
Output is correct |
13 |
Correct |
5 ms |
8280 KB |
Output is correct |
14 |
Correct |
36 ms |
14536 KB |
Output is correct |
15 |
Correct |
130 ms |
17256 KB |
Output is correct |
16 |
Correct |
4 ms |
8280 KB |
Output is correct |
17 |
Correct |
4 ms |
8284 KB |
Output is correct |
18 |
Correct |
57 ms |
16544 KB |
Output is correct |
19 |
Correct |
3 ms |
8284 KB |
Output is correct |
20 |
Correct |
3 ms |
8284 KB |
Output is correct |
21 |
Correct |
7 ms |
8284 KB |
Output is correct |
22 |
Correct |
4 ms |
8284 KB |
Output is correct |
23 |
Correct |
36 ms |
14512 KB |
Output is correct |
24 |
Correct |
130 ms |
17348 KB |
Output is correct |
25 |
Correct |
4 ms |
8280 KB |
Output is correct |
26 |
Correct |
5 ms |
8504 KB |
Output is correct |
27 |
Correct |
78 ms |
23128 KB |
Output is correct |
28 |
Correct |
58 ms |
16540 KB |
Output is correct |
29 |
Correct |
68 ms |
15556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8028 KB |
Output is correct |
2 |
Correct |
3 ms |
8284 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8028 KB |
Output is correct |
6 |
Correct |
3 ms |
8228 KB |
Output is correct |
7 |
Correct |
4 ms |
8280 KB |
Output is correct |
8 |
Correct |
4 ms |
8280 KB |
Output is correct |
9 |
Correct |
5 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8184 KB |
Output is correct |
12 |
Correct |
4 ms |
8280 KB |
Output is correct |
13 |
Correct |
3 ms |
8028 KB |
Output is correct |
14 |
Correct |
4 ms |
8028 KB |
Output is correct |
15 |
Correct |
3 ms |
8284 KB |
Output is correct |
16 |
Correct |
5 ms |
8028 KB |
Output is correct |
17 |
Correct |
4 ms |
8028 KB |
Output is correct |
18 |
Correct |
4 ms |
8028 KB |
Output is correct |
19 |
Correct |
4 ms |
8028 KB |
Output is correct |
20 |
Correct |
4 ms |
8280 KB |
Output is correct |
21 |
Correct |
4 ms |
8284 KB |
Output is correct |
22 |
Correct |
3 ms |
8028 KB |
Output is correct |
23 |
Correct |
4 ms |
8284 KB |
Output is correct |
24 |
Correct |
3 ms |
8284 KB |
Output is correct |
25 |
Correct |
3 ms |
8284 KB |
Output is correct |
26 |
Correct |
3 ms |
8028 KB |
Output is correct |
27 |
Correct |
3 ms |
8028 KB |
Output is correct |
28 |
Correct |
4 ms |
8028 KB |
Output is correct |
29 |
Correct |
3 ms |
8028 KB |
Output is correct |
30 |
Correct |
3 ms |
8284 KB |
Output is correct |
31 |
Correct |
4 ms |
8284 KB |
Output is correct |
32 |
Correct |
3 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8028 KB |
Output is correct |
2 |
Correct |
3 ms |
8284 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8028 KB |
Output is correct |
6 |
Correct |
3 ms |
8228 KB |
Output is correct |
7 |
Correct |
4 ms |
8280 KB |
Output is correct |
8 |
Correct |
4 ms |
8280 KB |
Output is correct |
9 |
Correct |
5 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8184 KB |
Output is correct |
12 |
Correct |
4 ms |
8280 KB |
Output is correct |
13 |
Correct |
3 ms |
8028 KB |
Output is correct |
14 |
Correct |
4 ms |
8028 KB |
Output is correct |
15 |
Correct |
3 ms |
8284 KB |
Output is correct |
16 |
Correct |
5 ms |
8028 KB |
Output is correct |
17 |
Correct |
4 ms |
8028 KB |
Output is correct |
18 |
Correct |
4 ms |
8028 KB |
Output is correct |
19 |
Correct |
4 ms |
8028 KB |
Output is correct |
20 |
Correct |
4 ms |
8280 KB |
Output is correct |
21 |
Correct |
4 ms |
8284 KB |
Output is correct |
22 |
Correct |
3 ms |
8028 KB |
Output is correct |
23 |
Correct |
4 ms |
8284 KB |
Output is correct |
24 |
Correct |
3 ms |
8284 KB |
Output is correct |
25 |
Correct |
3 ms |
8284 KB |
Output is correct |
26 |
Correct |
3 ms |
8028 KB |
Output is correct |
27 |
Correct |
3 ms |
8028 KB |
Output is correct |
28 |
Correct |
4 ms |
8028 KB |
Output is correct |
29 |
Correct |
3 ms |
8028 KB |
Output is correct |
30 |
Correct |
3 ms |
8284 KB |
Output is correct |
31 |
Correct |
4 ms |
8284 KB |
Output is correct |
32 |
Correct |
3 ms |
8284 KB |
Output is correct |
33 |
Correct |
4 ms |
8284 KB |
Output is correct |
34 |
Correct |
4 ms |
8428 KB |
Output is correct |
35 |
Correct |
4 ms |
8284 KB |
Output is correct |
36 |
Correct |
5 ms |
8284 KB |
Output is correct |
37 |
Correct |
4 ms |
8192 KB |
Output is correct |
38 |
Correct |
4 ms |
8284 KB |
Output is correct |
39 |
Correct |
5 ms |
8280 KB |
Output is correct |
40 |
Correct |
4 ms |
8348 KB |
Output is correct |
41 |
Correct |
4 ms |
8284 KB |
Output is correct |
42 |
Correct |
4 ms |
8348 KB |
Output is correct |
43 |
Correct |
5 ms |
8284 KB |
Output is correct |
44 |
Correct |
4 ms |
8284 KB |
Output is correct |
45 |
Correct |
5 ms |
8284 KB |
Output is correct |
46 |
Correct |
5 ms |
8284 KB |
Output is correct |
47 |
Correct |
5 ms |
8384 KB |
Output is correct |
48 |
Correct |
4 ms |
8284 KB |
Output is correct |
49 |
Correct |
5 ms |
8284 KB |
Output is correct |
50 |
Correct |
4 ms |
8280 KB |
Output is correct |
51 |
Correct |
4 ms |
8284 KB |
Output is correct |
52 |
Correct |
5 ms |
8284 KB |
Output is correct |
53 |
Correct |
5 ms |
8284 KB |
Output is correct |
54 |
Correct |
5 ms |
8284 KB |
Output is correct |
55 |
Correct |
4 ms |
8424 KB |
Output is correct |
56 |
Correct |
7 ms |
8284 KB |
Output is correct |
57 |
Correct |
4 ms |
8284 KB |
Output is correct |
58 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
3 ms |
8024 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8284 KB |
Output is correct |
7 |
Correct |
58 ms |
17936 KB |
Output is correct |
8 |
Correct |
68 ms |
18168 KB |
Output is correct |
9 |
Correct |
64 ms |
18264 KB |
Output is correct |
10 |
Correct |
4 ms |
8028 KB |
Output is correct |
11 |
Correct |
4 ms |
8024 KB |
Output is correct |
12 |
Correct |
4 ms |
8284 KB |
Output is correct |
13 |
Correct |
5 ms |
8280 KB |
Output is correct |
14 |
Correct |
36 ms |
14536 KB |
Output is correct |
15 |
Correct |
130 ms |
17256 KB |
Output is correct |
16 |
Correct |
4 ms |
8280 KB |
Output is correct |
17 |
Correct |
4 ms |
8284 KB |
Output is correct |
18 |
Correct |
57 ms |
16544 KB |
Output is correct |
19 |
Correct |
3 ms |
8284 KB |
Output is correct |
20 |
Correct |
3 ms |
8284 KB |
Output is correct |
21 |
Correct |
7 ms |
8284 KB |
Output is correct |
22 |
Correct |
4 ms |
8284 KB |
Output is correct |
23 |
Correct |
36 ms |
14512 KB |
Output is correct |
24 |
Correct |
130 ms |
17348 KB |
Output is correct |
25 |
Correct |
4 ms |
8280 KB |
Output is correct |
26 |
Correct |
5 ms |
8504 KB |
Output is correct |
27 |
Correct |
78 ms |
23128 KB |
Output is correct |
28 |
Correct |
58 ms |
16540 KB |
Output is correct |
29 |
Correct |
68 ms |
15556 KB |
Output is correct |
30 |
Correct |
3 ms |
8028 KB |
Output is correct |
31 |
Correct |
3 ms |
8284 KB |
Output is correct |
32 |
Correct |
4 ms |
8284 KB |
Output is correct |
33 |
Correct |
4 ms |
8028 KB |
Output is correct |
34 |
Correct |
4 ms |
8028 KB |
Output is correct |
35 |
Correct |
3 ms |
8228 KB |
Output is correct |
36 |
Correct |
4 ms |
8280 KB |
Output is correct |
37 |
Correct |
4 ms |
8280 KB |
Output is correct |
38 |
Correct |
5 ms |
8284 KB |
Output is correct |
39 |
Correct |
4 ms |
8284 KB |
Output is correct |
40 |
Correct |
4 ms |
8184 KB |
Output is correct |
41 |
Correct |
4 ms |
8280 KB |
Output is correct |
42 |
Correct |
3 ms |
8028 KB |
Output is correct |
43 |
Correct |
4 ms |
8028 KB |
Output is correct |
44 |
Correct |
3 ms |
8284 KB |
Output is correct |
45 |
Correct |
5 ms |
8028 KB |
Output is correct |
46 |
Correct |
4 ms |
8028 KB |
Output is correct |
47 |
Correct |
4 ms |
8028 KB |
Output is correct |
48 |
Correct |
4 ms |
8028 KB |
Output is correct |
49 |
Correct |
4 ms |
8280 KB |
Output is correct |
50 |
Correct |
4 ms |
8284 KB |
Output is correct |
51 |
Correct |
3 ms |
8028 KB |
Output is correct |
52 |
Correct |
4 ms |
8284 KB |
Output is correct |
53 |
Correct |
3 ms |
8284 KB |
Output is correct |
54 |
Correct |
3 ms |
8284 KB |
Output is correct |
55 |
Correct |
3 ms |
8028 KB |
Output is correct |
56 |
Correct |
3 ms |
8028 KB |
Output is correct |
57 |
Correct |
4 ms |
8028 KB |
Output is correct |
58 |
Correct |
3 ms |
8028 KB |
Output is correct |
59 |
Correct |
3 ms |
8284 KB |
Output is correct |
60 |
Correct |
4 ms |
8284 KB |
Output is correct |
61 |
Correct |
3 ms |
8284 KB |
Output is correct |
62 |
Correct |
4 ms |
8284 KB |
Output is correct |
63 |
Correct |
4 ms |
8428 KB |
Output is correct |
64 |
Correct |
4 ms |
8284 KB |
Output is correct |
65 |
Correct |
5 ms |
8284 KB |
Output is correct |
66 |
Correct |
4 ms |
8192 KB |
Output is correct |
67 |
Correct |
4 ms |
8284 KB |
Output is correct |
68 |
Correct |
5 ms |
8280 KB |
Output is correct |
69 |
Correct |
4 ms |
8348 KB |
Output is correct |
70 |
Correct |
4 ms |
8284 KB |
Output is correct |
71 |
Correct |
4 ms |
8348 KB |
Output is correct |
72 |
Correct |
5 ms |
8284 KB |
Output is correct |
73 |
Correct |
4 ms |
8284 KB |
Output is correct |
74 |
Correct |
5 ms |
8284 KB |
Output is correct |
75 |
Correct |
5 ms |
8284 KB |
Output is correct |
76 |
Correct |
5 ms |
8384 KB |
Output is correct |
77 |
Correct |
4 ms |
8284 KB |
Output is correct |
78 |
Correct |
5 ms |
8284 KB |
Output is correct |
79 |
Correct |
4 ms |
8280 KB |
Output is correct |
80 |
Correct |
4 ms |
8284 KB |
Output is correct |
81 |
Correct |
5 ms |
8284 KB |
Output is correct |
82 |
Correct |
5 ms |
8284 KB |
Output is correct |
83 |
Correct |
5 ms |
8284 KB |
Output is correct |
84 |
Correct |
4 ms |
8424 KB |
Output is correct |
85 |
Correct |
7 ms |
8284 KB |
Output is correct |
86 |
Correct |
4 ms |
8284 KB |
Output is correct |
87 |
Correct |
4 ms |
8284 KB |
Output is correct |
88 |
Correct |
83 ms |
15668 KB |
Output is correct |
89 |
Correct |
82 ms |
15672 KB |
Output is correct |
90 |
Correct |
79 ms |
17384 KB |
Output is correct |
91 |
Correct |
38 ms |
13952 KB |
Output is correct |
92 |
Correct |
40 ms |
13904 KB |
Output is correct |
93 |
Correct |
45 ms |
14616 KB |
Output is correct |
94 |
Correct |
40 ms |
14464 KB |
Output is correct |
95 |
Correct |
153 ms |
18212 KB |
Output is correct |
96 |
Correct |
146 ms |
16832 KB |
Output is correct |
97 |
Correct |
145 ms |
16692 KB |
Output is correct |
98 |
Correct |
125 ms |
16704 KB |
Output is correct |
99 |
Correct |
58 ms |
16584 KB |
Output is correct |
100 |
Correct |
60 ms |
16656 KB |
Output is correct |
101 |
Correct |
40 ms |
13904 KB |
Output is correct |
102 |
Correct |
37 ms |
13908 KB |
Output is correct |
103 |
Correct |
42 ms |
14500 KB |
Output is correct |
104 |
Correct |
49 ms |
14544 KB |
Output is correct |
105 |
Correct |
143 ms |
18336 KB |
Output is correct |
106 |
Correct |
138 ms |
18196 KB |
Output is correct |
107 |
Correct |
121 ms |
23156 KB |
Output is correct |
108 |
Correct |
143 ms |
23132 KB |
Output is correct |
109 |
Correct |
69 ms |
16536 KB |
Output is correct |
110 |
Correct |
64 ms |
16540 KB |
Output is correct |
111 |
Correct |
81 ms |
15616 KB |
Output is correct |
112 |
Correct |
82 ms |
15588 KB |
Output is correct |