//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma traget("avx,avx2")
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define el '\n'
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define point pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
#include <random>
mt19937 rnd(time(0));
const ll INF = 2e18 + 10;
const ll inf = 1e9 + 10;
const ll N = 2e5 + 10;
const ll mod = 1e9 + 7;
const ll LOG = 20;
vector <point> gr[N];
void solve() {
ll n, m;
cin >> n >> m;
ll s, t, l, k;
cin >> s >> t >> l >> k;
for (ll i = 0; i < m; i++) {
ll u, v, c;
cin >> u >> v >> c;
gr[u].pb({v, c});
gr[v].pb({u, c});
}
auto bfs = [&](ll start) -> vector <ll> {
vector <ll> dist(n + 1, INF);
dist[start] = 0;
dist[0] = -INF;
set <point> st;
st.insert({dist[start], start});
while (!st.empty()) {
ll v = st.begin()->ss;
st.erase(st.begin());
for (point to : gr[v]) {
if (dist[to.ff] > dist[v] + to.ss) {
st.erase({dist[to.ff], to.ff});
dist[to.ff] = dist[v] + to.ss;
st.insert({dist[to.ff], to.ff});
}
}
}
return dist;
};
vector <ll> dist[2];
dist[0] = bfs(s);
dist[1] = bfs(t);
if (dist[0][t] <= k)
return void(cout << n * (n - 1) / 2 << el);
ll ans = 0;
sort(all(dist[0]));
sort(all(dist[1]));
for (ll i = 1; i <= n; i++) {
ll lb, rb;
lb = 0, rb = n + 1;
while (lb + 1 < rb) {
ll mid = (lb + rb) >> 1;
if (dist[0][i] + l + dist[1][mid] <= k)
lb = mid;
else
rb = mid;
}
ans += lb;
lb = 0, rb = n + 1;
while (lb + 1 < rb) {
ll mid = (lb + rb) >> 1;
if (dist[0][mid] + l + dist[1][i] <= k)
lb = mid;
else
rb = mid;
}
ans += lb;
}
cout << ans / 2 << el;
return;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("deleg.in", "r", stdin);
//freopen("deleg.out", "w", stdout);
int tests = 1;
//cin >> tests;
while (tests--)
solve();
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4952 KB |
Output is correct |
5 |
Correct |
4 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5280 KB |
Output is correct |
7 |
Correct |
96 ms |
23104 KB |
Output is correct |
8 |
Correct |
127 ms |
23180 KB |
Output is correct |
9 |
Correct |
120 ms |
25552 KB |
Output is correct |
10 |
Correct |
3 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
5212 KB |
Output is correct |
13 |
Correct |
4 ms |
5212 KB |
Output is correct |
14 |
Correct |
62 ms |
15052 KB |
Output is correct |
15 |
Correct |
232 ms |
23512 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
101 ms |
20596 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
3 ms |
5212 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
48 ms |
14944 KB |
Output is correct |
24 |
Correct |
214 ms |
23352 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5548 KB |
Output is correct |
27 |
Correct |
185 ms |
33064 KB |
Output is correct |
28 |
Correct |
114 ms |
23080 KB |
Output is correct |
29 |
Correct |
79 ms |
18352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
4 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5160 KB |
Output is correct |
4 |
Correct |
4 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
3 ms |
4996 KB |
Output is correct |
12 |
Correct |
2 ms |
5156 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
4 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4952 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4952 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
5168 KB |
Output is correct |
26 |
Correct |
3 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
3 ms |
4956 KB |
Output is correct |
31 |
Correct |
3 ms |
5156 KB |
Output is correct |
32 |
Correct |
3 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
4 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5160 KB |
Output is correct |
4 |
Correct |
4 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
3 ms |
4996 KB |
Output is correct |
12 |
Correct |
2 ms |
5156 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
4 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4952 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4952 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
5168 KB |
Output is correct |
26 |
Correct |
3 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
3 ms |
4956 KB |
Output is correct |
31 |
Correct |
3 ms |
5156 KB |
Output is correct |
32 |
Correct |
3 ms |
4956 KB |
Output is correct |
33 |
Correct |
5 ms |
5212 KB |
Output is correct |
34 |
Correct |
5 ms |
5456 KB |
Output is correct |
35 |
Correct |
3 ms |
5212 KB |
Output is correct |
36 |
Correct |
4 ms |
5212 KB |
Output is correct |
37 |
Correct |
3 ms |
5208 KB |
Output is correct |
38 |
Correct |
2 ms |
5208 KB |
Output is correct |
39 |
Correct |
3 ms |
5212 KB |
Output is correct |
40 |
Correct |
5 ms |
5492 KB |
Output is correct |
41 |
Correct |
3 ms |
5212 KB |
Output is correct |
42 |
Correct |
3 ms |
5212 KB |
Output is correct |
43 |
Correct |
5 ms |
5268 KB |
Output is correct |
44 |
Correct |
4 ms |
5212 KB |
Output is correct |
45 |
Correct |
5 ms |
5212 KB |
Output is correct |
46 |
Correct |
4 ms |
5212 KB |
Output is correct |
47 |
Correct |
5 ms |
5212 KB |
Output is correct |
48 |
Correct |
3 ms |
5208 KB |
Output is correct |
49 |
Correct |
3 ms |
5212 KB |
Output is correct |
50 |
Correct |
3 ms |
5172 KB |
Output is correct |
51 |
Correct |
5 ms |
5212 KB |
Output is correct |
52 |
Correct |
4 ms |
5212 KB |
Output is correct |
53 |
Correct |
4 ms |
5468 KB |
Output is correct |
54 |
Correct |
5 ms |
5468 KB |
Output is correct |
55 |
Correct |
3 ms |
5212 KB |
Output is correct |
56 |
Correct |
3 ms |
5208 KB |
Output is correct |
57 |
Correct |
3 ms |
5244 KB |
Output is correct |
58 |
Correct |
6 ms |
5292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4952 KB |
Output is correct |
5 |
Correct |
4 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5280 KB |
Output is correct |
7 |
Correct |
96 ms |
23104 KB |
Output is correct |
8 |
Correct |
127 ms |
23180 KB |
Output is correct |
9 |
Correct |
120 ms |
25552 KB |
Output is correct |
10 |
Correct |
3 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
5212 KB |
Output is correct |
13 |
Correct |
4 ms |
5212 KB |
Output is correct |
14 |
Correct |
62 ms |
15052 KB |
Output is correct |
15 |
Correct |
232 ms |
23512 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
101 ms |
20596 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
3 ms |
5212 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
48 ms |
14944 KB |
Output is correct |
24 |
Correct |
214 ms |
23352 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5548 KB |
Output is correct |
27 |
Correct |
185 ms |
33064 KB |
Output is correct |
28 |
Correct |
114 ms |
23080 KB |
Output is correct |
29 |
Correct |
79 ms |
18352 KB |
Output is correct |
30 |
Correct |
2 ms |
4956 KB |
Output is correct |
31 |
Correct |
4 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
5160 KB |
Output is correct |
33 |
Correct |
4 ms |
4956 KB |
Output is correct |
34 |
Correct |
3 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
5212 KB |
Output is correct |
40 |
Correct |
3 ms |
4996 KB |
Output is correct |
41 |
Correct |
2 ms |
5156 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
4 ms |
4956 KB |
Output is correct |
44 |
Correct |
3 ms |
4952 KB |
Output is correct |
45 |
Correct |
3 ms |
4956 KB |
Output is correct |
46 |
Correct |
2 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
4956 KB |
Output is correct |
51 |
Correct |
2 ms |
4952 KB |
Output is correct |
52 |
Correct |
3 ms |
4956 KB |
Output is correct |
53 |
Correct |
2 ms |
4956 KB |
Output is correct |
54 |
Correct |
2 ms |
5168 KB |
Output is correct |
55 |
Correct |
3 ms |
4956 KB |
Output is correct |
56 |
Correct |
2 ms |
4956 KB |
Output is correct |
57 |
Correct |
2 ms |
4956 KB |
Output is correct |
58 |
Correct |
2 ms |
4956 KB |
Output is correct |
59 |
Correct |
3 ms |
4956 KB |
Output is correct |
60 |
Correct |
3 ms |
5156 KB |
Output is correct |
61 |
Correct |
3 ms |
4956 KB |
Output is correct |
62 |
Correct |
5 ms |
5212 KB |
Output is correct |
63 |
Correct |
5 ms |
5456 KB |
Output is correct |
64 |
Correct |
3 ms |
5212 KB |
Output is correct |
65 |
Correct |
4 ms |
5212 KB |
Output is correct |
66 |
Correct |
3 ms |
5208 KB |
Output is correct |
67 |
Correct |
2 ms |
5208 KB |
Output is correct |
68 |
Correct |
3 ms |
5212 KB |
Output is correct |
69 |
Correct |
5 ms |
5492 KB |
Output is correct |
70 |
Correct |
3 ms |
5212 KB |
Output is correct |
71 |
Correct |
3 ms |
5212 KB |
Output is correct |
72 |
Correct |
5 ms |
5268 KB |
Output is correct |
73 |
Correct |
4 ms |
5212 KB |
Output is correct |
74 |
Correct |
5 ms |
5212 KB |
Output is correct |
75 |
Correct |
4 ms |
5212 KB |
Output is correct |
76 |
Correct |
5 ms |
5212 KB |
Output is correct |
77 |
Correct |
3 ms |
5208 KB |
Output is correct |
78 |
Correct |
3 ms |
5212 KB |
Output is correct |
79 |
Correct |
3 ms |
5172 KB |
Output is correct |
80 |
Correct |
5 ms |
5212 KB |
Output is correct |
81 |
Correct |
4 ms |
5212 KB |
Output is correct |
82 |
Correct |
4 ms |
5468 KB |
Output is correct |
83 |
Correct |
5 ms |
5468 KB |
Output is correct |
84 |
Correct |
3 ms |
5212 KB |
Output is correct |
85 |
Correct |
3 ms |
5208 KB |
Output is correct |
86 |
Correct |
3 ms |
5244 KB |
Output is correct |
87 |
Correct |
6 ms |
5292 KB |
Output is correct |
88 |
Correct |
103 ms |
23892 KB |
Output is correct |
89 |
Correct |
112 ms |
23980 KB |
Output is correct |
90 |
Correct |
109 ms |
23888 KB |
Output is correct |
91 |
Correct |
42 ms |
18660 KB |
Output is correct |
92 |
Correct |
41 ms |
18880 KB |
Output is correct |
93 |
Correct |
46 ms |
15696 KB |
Output is correct |
94 |
Correct |
46 ms |
15744 KB |
Output is correct |
95 |
Correct |
222 ms |
25000 KB |
Output is correct |
96 |
Correct |
187 ms |
25020 KB |
Output is correct |
97 |
Correct |
174 ms |
22920 KB |
Output is correct |
98 |
Correct |
148 ms |
23120 KB |
Output is correct |
99 |
Correct |
80 ms |
22040 KB |
Output is correct |
100 |
Correct |
77 ms |
21964 KB |
Output is correct |
101 |
Correct |
40 ms |
18772 KB |
Output is correct |
102 |
Correct |
42 ms |
18728 KB |
Output is correct |
103 |
Correct |
46 ms |
15696 KB |
Output is correct |
104 |
Correct |
45 ms |
15640 KB |
Output is correct |
105 |
Correct |
243 ms |
24828 KB |
Output is correct |
106 |
Correct |
232 ms |
25052 KB |
Output is correct |
107 |
Correct |
247 ms |
34484 KB |
Output is correct |
108 |
Correct |
264 ms |
34740 KB |
Output is correct |
109 |
Correct |
126 ms |
24396 KB |
Output is correct |
110 |
Correct |
122 ms |
24368 KB |
Output is correct |
111 |
Correct |
77 ms |
18516 KB |
Output is correct |
112 |
Correct |
76 ms |
18516 KB |
Output is correct |