#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MAXN = 200001;
const ll INF = (ll)(1e18);
struct Node {
int u;
ll dis;
};
struct cmp {
bool operator()(const Node &a, const Node &b) const {
return a.dis > b.dis;
}
};
int n, m, s, t, l;
ll dist[2][MAXN], ans, k;
bool vis[2][MAXN];
vector<pii> e[MAXN];
void dij(int S, bool op) {
priority_queue<Node, vector<Node>, cmp> pq;
for(int i = 1; i <= n; ++i) {
dist[op][i] = INF;
vis[op][i] = 0;
}
dist[op][S] = 0;
pq.push({S, 0});
for(; !pq.empty(); ) {
auto [u, dis] = pq.top();
pq.pop();
if(vis[op][u]) {
continue;
}
vis[op][u] = 1;
for(auto [v, w] : e[u]) {
if(dis + w < dist[op][v]) {
dist[op][v] = dis + w;
pq.push({v, dis + w});
}
}
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m >> s >> t >> l >> k;
for(int i = 1, u, v, w; i <= m; ++i) {
cin >> u >> v >> w;
e[u].emplace_back(v, w);
e[v].emplace_back(u, w);
}
dij(s, 0);
dij(t, 1);
if(dist[0][t] <= k) {
cout << 1ll * n * (n - 1) / 2;
return 0;
}
sort(dist[0] + 1, dist[0] + n + 1);
sort(dist[1] + 1, dist[1] + n + 1);
for(int i = 1, j = n; i <= n; ++i) {
for(; j > 0 && dist[0][i] + dist[1][j] + l > k; --j) {
}
ans += j;
}
cout << ans;
return 0;
}
Compilation message
Main.cpp: In function 'void dij(int, bool)':
Main.cpp:34:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | auto [u, dis] = pq.top();
| ^
Main.cpp:40:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
40 | for(auto [v, w] : e[u]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5180 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
50 ms |
20436 KB |
Output is correct |
8 |
Correct |
65 ms |
20556 KB |
Output is correct |
9 |
Correct |
62 ms |
23792 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5208 KB |
Output is correct |
14 |
Correct |
32 ms |
14172 KB |
Output is correct |
15 |
Correct |
106 ms |
19536 KB |
Output is correct |
16 |
Correct |
2 ms |
4952 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
71 ms |
17820 KB |
Output is correct |
19 |
Correct |
2 ms |
4952 KB |
Output is correct |
20 |
Correct |
4 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5208 KB |
Output is correct |
22 |
Correct |
3 ms |
5180 KB |
Output is correct |
23 |
Correct |
35 ms |
14332 KB |
Output is correct |
24 |
Correct |
104 ms |
19500 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5720 KB |
Output is correct |
27 |
Correct |
75 ms |
26780 KB |
Output is correct |
28 |
Correct |
52 ms |
17500 KB |
Output is correct |
29 |
Correct |
77 ms |
15444 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 |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5188 KB |
Output is correct |
8 |
Correct |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
5052 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4952 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
5168 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4952 KB |
Output is correct |
27 |
Correct |
2 ms |
4952 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
3 ms |
4956 KB |
Output is correct |
30 |
Correct |
2 ms |
4956 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 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 |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5188 KB |
Output is correct |
8 |
Correct |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
5052 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4952 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
5168 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4952 KB |
Output is correct |
27 |
Correct |
2 ms |
4952 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
3 ms |
4956 KB |
Output is correct |
30 |
Correct |
2 ms |
4956 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
3 ms |
5212 KB |
Output is correct |
34 |
Correct |
3 ms |
5212 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
3 ms |
5432 KB |
Output is correct |
37 |
Correct |
3 ms |
5204 KB |
Output is correct |
38 |
Correct |
3 ms |
5144 KB |
Output is correct |
39 |
Correct |
4 ms |
5212 KB |
Output is correct |
40 |
Correct |
4 ms |
5468 KB |
Output is correct |
41 |
Correct |
3 ms |
5248 KB |
Output is correct |
42 |
Correct |
3 ms |
5176 KB |
Output is correct |
43 |
Correct |
4 ms |
5468 KB |
Output is correct |
44 |
Correct |
3 ms |
5212 KB |
Output is correct |
45 |
Correct |
3 ms |
5212 KB |
Output is correct |
46 |
Correct |
3 ms |
5272 KB |
Output is correct |
47 |
Correct |
3 ms |
5212 KB |
Output is correct |
48 |
Correct |
3 ms |
5172 KB |
Output is correct |
49 |
Correct |
3 ms |
5208 KB |
Output is correct |
50 |
Correct |
3 ms |
5212 KB |
Output is correct |
51 |
Correct |
4 ms |
5212 KB |
Output is correct |
52 |
Correct |
3 ms |
5212 KB |
Output is correct |
53 |
Correct |
3 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 |
5212 KB |
Output is correct |
57 |
Correct |
3 ms |
5176 KB |
Output is correct |
58 |
Correct |
3 ms |
5212 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 |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5180 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
50 ms |
20436 KB |
Output is correct |
8 |
Correct |
65 ms |
20556 KB |
Output is correct |
9 |
Correct |
62 ms |
23792 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5208 KB |
Output is correct |
14 |
Correct |
32 ms |
14172 KB |
Output is correct |
15 |
Correct |
106 ms |
19536 KB |
Output is correct |
16 |
Correct |
2 ms |
4952 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
71 ms |
17820 KB |
Output is correct |
19 |
Correct |
2 ms |
4952 KB |
Output is correct |
20 |
Correct |
4 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5208 KB |
Output is correct |
22 |
Correct |
3 ms |
5180 KB |
Output is correct |
23 |
Correct |
35 ms |
14332 KB |
Output is correct |
24 |
Correct |
104 ms |
19500 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5720 KB |
Output is correct |
27 |
Correct |
75 ms |
26780 KB |
Output is correct |
28 |
Correct |
52 ms |
17500 KB |
Output is correct |
29 |
Correct |
77 ms |
15444 KB |
Output is correct |
30 |
Correct |
2 ms |
4952 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
2 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
5188 KB |
Output is correct |
37 |
Correct |
2 ms |
5208 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4952 KB |
Output is correct |
40 |
Correct |
2 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
5052 KB |
Output is correct |
43 |
Correct |
2 ms |
4956 KB |
Output is correct |
44 |
Correct |
2 ms |
4952 KB |
Output is correct |
45 |
Correct |
2 ms |
4956 KB |
Output is correct |
46 |
Correct |
2 ms |
4952 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
5168 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
4952 KB |
Output is correct |
51 |
Correct |
2 ms |
4956 KB |
Output is correct |
52 |
Correct |
2 ms |
4956 KB |
Output is correct |
53 |
Correct |
2 ms |
4956 KB |
Output is correct |
54 |
Correct |
2 ms |
4956 KB |
Output is correct |
55 |
Correct |
2 ms |
4952 KB |
Output is correct |
56 |
Correct |
2 ms |
4952 KB |
Output is correct |
57 |
Correct |
2 ms |
4956 KB |
Output is correct |
58 |
Correct |
3 ms |
4956 KB |
Output is correct |
59 |
Correct |
2 ms |
4956 KB |
Output is correct |
60 |
Correct |
2 ms |
4956 KB |
Output is correct |
61 |
Correct |
2 ms |
4956 KB |
Output is correct |
62 |
Correct |
3 ms |
5212 KB |
Output is correct |
63 |
Correct |
3 ms |
5212 KB |
Output is correct |
64 |
Correct |
2 ms |
5212 KB |
Output is correct |
65 |
Correct |
3 ms |
5432 KB |
Output is correct |
66 |
Correct |
3 ms |
5204 KB |
Output is correct |
67 |
Correct |
3 ms |
5144 KB |
Output is correct |
68 |
Correct |
4 ms |
5212 KB |
Output is correct |
69 |
Correct |
4 ms |
5468 KB |
Output is correct |
70 |
Correct |
3 ms |
5248 KB |
Output is correct |
71 |
Correct |
3 ms |
5176 KB |
Output is correct |
72 |
Correct |
4 ms |
5468 KB |
Output is correct |
73 |
Correct |
3 ms |
5212 KB |
Output is correct |
74 |
Correct |
3 ms |
5212 KB |
Output is correct |
75 |
Correct |
3 ms |
5272 KB |
Output is correct |
76 |
Correct |
3 ms |
5212 KB |
Output is correct |
77 |
Correct |
3 ms |
5172 KB |
Output is correct |
78 |
Correct |
3 ms |
5208 KB |
Output is correct |
79 |
Correct |
3 ms |
5212 KB |
Output is correct |
80 |
Correct |
4 ms |
5212 KB |
Output is correct |
81 |
Correct |
3 ms |
5212 KB |
Output is correct |
82 |
Correct |
3 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 |
5212 KB |
Output is correct |
86 |
Correct |
3 ms |
5176 KB |
Output is correct |
87 |
Correct |
3 ms |
5212 KB |
Output is correct |
88 |
Correct |
74 ms |
20660 KB |
Output is correct |
89 |
Correct |
78 ms |
20536 KB |
Output is correct |
90 |
Correct |
80 ms |
20524 KB |
Output is correct |
91 |
Correct |
40 ms |
14208 KB |
Output is correct |
92 |
Correct |
40 ms |
14168 KB |
Output is correct |
93 |
Correct |
36 ms |
15132 KB |
Output is correct |
94 |
Correct |
36 ms |
14928 KB |
Output is correct |
95 |
Correct |
162 ms |
21672 KB |
Output is correct |
96 |
Correct |
111 ms |
21500 KB |
Output is correct |
97 |
Correct |
135 ms |
19300 KB |
Output is correct |
98 |
Correct |
121 ms |
19280 KB |
Output is correct |
99 |
Correct |
62 ms |
19280 KB |
Output is correct |
100 |
Correct |
64 ms |
19280 KB |
Output is correct |
101 |
Correct |
42 ms |
14164 KB |
Output is correct |
102 |
Correct |
43 ms |
14160 KB |
Output is correct |
103 |
Correct |
36 ms |
14940 KB |
Output is correct |
104 |
Correct |
47 ms |
14932 KB |
Output is correct |
105 |
Correct |
139 ms |
21696 KB |
Output is correct |
106 |
Correct |
131 ms |
21700 KB |
Output is correct |
107 |
Correct |
146 ms |
28024 KB |
Output is correct |
108 |
Correct |
139 ms |
28160 KB |
Output is correct |
109 |
Correct |
72 ms |
18772 KB |
Output is correct |
110 |
Correct |
78 ms |
18640 KB |
Output is correct |
111 |
Correct |
84 ms |
16692 KB |
Output is correct |
112 |
Correct |
81 ms |
16592 KB |
Output is correct |