#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000005;
const long long inf = (1LL << 61);
int n, m, s, t;
long long L, K;
long long ds[maxn], dt[maxn];
pair<long long, long long> d[maxn];
vector<pair<int, int>> g[maxn];
void dijkstra(int start, long long dist[])
{
for (int i = 1; i <= n; ++i)
{
dist[i] = inf;
}
priority_queue<pair<long long, int>> pq;
pq.push({0, start});
dist[start] = 0;
bool visited[n + 1] = {};
while (!pq.empty())
{
auto top = pq.top();
pq.pop();
int node = top.second;
long long curr = -top.first;
if (visited[node] == true) continue;
visited[node] = true;
for (int i = 0; i < g[node].size(); ++i)
{
if (dist[g[node][i].first] > curr + g[node][i].second)
{
dist[g[node][i].first] = curr + g[node][i].second;
pq.push({-dist[g[node][i].first], g[node][i].first});
}
}
}
}
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n >> m >> s >> t >> L >> K;
for (int i = 1; i <= m; ++i)
{
int x, y, w;
cin >> x >> y >> w;
g[x].push_back({y, w});
g[y].push_back({x, w});
}
dijkstra(s, ds);
dijkstra(t, dt);
if (ds[t] <= K)
{
cout << ((1LL * n) * (1LL * (n - 1))) / 2 << endl;
return 0;
}
for (int i = 1; i <= n; ++i)
{
d[i] = {ds[i], dt[i]};
}
sort(d + 1, d + n + 1);
long long ans = 0;
for (int i = 2; i <= n; ++i)
{
if (d[i].second == inf) continue;
int l = 1;
int r = i - 1;
while (l <= r)
{
int mid = (l + r) / 2;
if (d[i].second + d[mid].first <= K - L)
{
l = mid + 1;
}
else
{
r = mid - 1;
}
}
ans += r;
}
cout << ans << endl;
return 0;
}
Compilation message
Main.cpp: In function 'void dijkstra(int, long long int*)':
Main.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < g[node].size(); ++i)
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
47192 KB |
Output is correct |
2 |
Correct |
20 ms |
47196 KB |
Output is correct |
3 |
Correct |
21 ms |
47196 KB |
Output is correct |
4 |
Correct |
21 ms |
47452 KB |
Output is correct |
5 |
Correct |
21 ms |
47452 KB |
Output is correct |
6 |
Correct |
21 ms |
47600 KB |
Output is correct |
7 |
Correct |
72 ms |
60272 KB |
Output is correct |
8 |
Correct |
84 ms |
60176 KB |
Output is correct |
9 |
Correct |
79 ms |
60784 KB |
Output is correct |
10 |
Correct |
21 ms |
47196 KB |
Output is correct |
11 |
Correct |
21 ms |
47452 KB |
Output is correct |
12 |
Correct |
21 ms |
47500 KB |
Output is correct |
13 |
Correct |
22 ms |
47452 KB |
Output is correct |
14 |
Correct |
61 ms |
57944 KB |
Output is correct |
15 |
Correct |
141 ms |
60808 KB |
Output is correct |
16 |
Correct |
21 ms |
47408 KB |
Output is correct |
17 |
Correct |
21 ms |
47452 KB |
Output is correct |
18 |
Correct |
82 ms |
59984 KB |
Output is correct |
19 |
Correct |
20 ms |
47196 KB |
Output is correct |
20 |
Correct |
20 ms |
47452 KB |
Output is correct |
21 |
Correct |
21 ms |
47580 KB |
Output is correct |
22 |
Correct |
23 ms |
47448 KB |
Output is correct |
23 |
Correct |
58 ms |
58040 KB |
Output is correct |
24 |
Correct |
157 ms |
60812 KB |
Output is correct |
25 |
Correct |
21 ms |
47452 KB |
Output is correct |
26 |
Correct |
21 ms |
47708 KB |
Output is correct |
27 |
Correct |
100 ms |
65608 KB |
Output is correct |
28 |
Correct |
72 ms |
57240 KB |
Output is correct |
29 |
Correct |
77 ms |
56912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
47196 KB |
Output is correct |
2 |
Correct |
22 ms |
47196 KB |
Output is correct |
3 |
Correct |
20 ms |
47208 KB |
Output is correct |
4 |
Correct |
20 ms |
47196 KB |
Output is correct |
5 |
Correct |
21 ms |
47452 KB |
Output is correct |
6 |
Correct |
21 ms |
47448 KB |
Output is correct |
7 |
Correct |
20 ms |
47192 KB |
Output is correct |
8 |
Correct |
21 ms |
47448 KB |
Output is correct |
9 |
Correct |
22 ms |
47192 KB |
Output is correct |
10 |
Correct |
21 ms |
47196 KB |
Output is correct |
11 |
Correct |
20 ms |
47452 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
22 ms |
47192 KB |
Output is correct |
14 |
Correct |
20 ms |
47440 KB |
Output is correct |
15 |
Correct |
20 ms |
47452 KB |
Output is correct |
16 |
Correct |
21 ms |
47452 KB |
Output is correct |
17 |
Correct |
20 ms |
47452 KB |
Output is correct |
18 |
Correct |
21 ms |
47244 KB |
Output is correct |
19 |
Correct |
20 ms |
47196 KB |
Output is correct |
20 |
Correct |
25 ms |
47424 KB |
Output is correct |
21 |
Correct |
21 ms |
47452 KB |
Output is correct |
22 |
Correct |
21 ms |
47192 KB |
Output is correct |
23 |
Correct |
20 ms |
47452 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
21 ms |
47216 KB |
Output is correct |
26 |
Correct |
21 ms |
47452 KB |
Output is correct |
27 |
Correct |
20 ms |
47196 KB |
Output is correct |
28 |
Correct |
20 ms |
47196 KB |
Output is correct |
29 |
Correct |
21 ms |
47192 KB |
Output is correct |
30 |
Correct |
25 ms |
47196 KB |
Output is correct |
31 |
Correct |
25 ms |
47196 KB |
Output is correct |
32 |
Correct |
20 ms |
47452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
47196 KB |
Output is correct |
2 |
Correct |
22 ms |
47196 KB |
Output is correct |
3 |
Correct |
20 ms |
47208 KB |
Output is correct |
4 |
Correct |
20 ms |
47196 KB |
Output is correct |
5 |
Correct |
21 ms |
47452 KB |
Output is correct |
6 |
Correct |
21 ms |
47448 KB |
Output is correct |
7 |
Correct |
20 ms |
47192 KB |
Output is correct |
8 |
Correct |
21 ms |
47448 KB |
Output is correct |
9 |
Correct |
22 ms |
47192 KB |
Output is correct |
10 |
Correct |
21 ms |
47196 KB |
Output is correct |
11 |
Correct |
20 ms |
47452 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
22 ms |
47192 KB |
Output is correct |
14 |
Correct |
20 ms |
47440 KB |
Output is correct |
15 |
Correct |
20 ms |
47452 KB |
Output is correct |
16 |
Correct |
21 ms |
47452 KB |
Output is correct |
17 |
Correct |
20 ms |
47452 KB |
Output is correct |
18 |
Correct |
21 ms |
47244 KB |
Output is correct |
19 |
Correct |
20 ms |
47196 KB |
Output is correct |
20 |
Correct |
25 ms |
47424 KB |
Output is correct |
21 |
Correct |
21 ms |
47452 KB |
Output is correct |
22 |
Correct |
21 ms |
47192 KB |
Output is correct |
23 |
Correct |
20 ms |
47452 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
21 ms |
47216 KB |
Output is correct |
26 |
Correct |
21 ms |
47452 KB |
Output is correct |
27 |
Correct |
20 ms |
47196 KB |
Output is correct |
28 |
Correct |
20 ms |
47196 KB |
Output is correct |
29 |
Correct |
21 ms |
47192 KB |
Output is correct |
30 |
Correct |
25 ms |
47196 KB |
Output is correct |
31 |
Correct |
25 ms |
47196 KB |
Output is correct |
32 |
Correct |
20 ms |
47452 KB |
Output is correct |
33 |
Correct |
21 ms |
47452 KB |
Output is correct |
34 |
Correct |
22 ms |
47604 KB |
Output is correct |
35 |
Correct |
21 ms |
47448 KB |
Output is correct |
36 |
Correct |
23 ms |
47516 KB |
Output is correct |
37 |
Correct |
21 ms |
47452 KB |
Output is correct |
38 |
Correct |
21 ms |
47452 KB |
Output is correct |
39 |
Correct |
25 ms |
47644 KB |
Output is correct |
40 |
Correct |
22 ms |
47708 KB |
Output is correct |
41 |
Correct |
22 ms |
47444 KB |
Output is correct |
42 |
Correct |
21 ms |
47448 KB |
Output is correct |
43 |
Correct |
21 ms |
47448 KB |
Output is correct |
44 |
Correct |
22 ms |
47452 KB |
Output is correct |
45 |
Correct |
22 ms |
47452 KB |
Output is correct |
46 |
Correct |
22 ms |
47452 KB |
Output is correct |
47 |
Correct |
22 ms |
47452 KB |
Output is correct |
48 |
Correct |
21 ms |
47452 KB |
Output is correct |
49 |
Correct |
22 ms |
47556 KB |
Output is correct |
50 |
Correct |
21 ms |
47456 KB |
Output is correct |
51 |
Correct |
27 ms |
47452 KB |
Output is correct |
52 |
Correct |
22 ms |
47452 KB |
Output is correct |
53 |
Correct |
22 ms |
47708 KB |
Output is correct |
54 |
Correct |
22 ms |
47660 KB |
Output is correct |
55 |
Correct |
21 ms |
47592 KB |
Output is correct |
56 |
Correct |
20 ms |
47604 KB |
Output is correct |
57 |
Correct |
21 ms |
47452 KB |
Output is correct |
58 |
Correct |
22 ms |
47452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
47192 KB |
Output is correct |
2 |
Correct |
20 ms |
47196 KB |
Output is correct |
3 |
Correct |
21 ms |
47196 KB |
Output is correct |
4 |
Correct |
21 ms |
47452 KB |
Output is correct |
5 |
Correct |
21 ms |
47452 KB |
Output is correct |
6 |
Correct |
21 ms |
47600 KB |
Output is correct |
7 |
Correct |
72 ms |
60272 KB |
Output is correct |
8 |
Correct |
84 ms |
60176 KB |
Output is correct |
9 |
Correct |
79 ms |
60784 KB |
Output is correct |
10 |
Correct |
21 ms |
47196 KB |
Output is correct |
11 |
Correct |
21 ms |
47452 KB |
Output is correct |
12 |
Correct |
21 ms |
47500 KB |
Output is correct |
13 |
Correct |
22 ms |
47452 KB |
Output is correct |
14 |
Correct |
61 ms |
57944 KB |
Output is correct |
15 |
Correct |
141 ms |
60808 KB |
Output is correct |
16 |
Correct |
21 ms |
47408 KB |
Output is correct |
17 |
Correct |
21 ms |
47452 KB |
Output is correct |
18 |
Correct |
82 ms |
59984 KB |
Output is correct |
19 |
Correct |
20 ms |
47196 KB |
Output is correct |
20 |
Correct |
20 ms |
47452 KB |
Output is correct |
21 |
Correct |
21 ms |
47580 KB |
Output is correct |
22 |
Correct |
23 ms |
47448 KB |
Output is correct |
23 |
Correct |
58 ms |
58040 KB |
Output is correct |
24 |
Correct |
157 ms |
60812 KB |
Output is correct |
25 |
Correct |
21 ms |
47452 KB |
Output is correct |
26 |
Correct |
21 ms |
47708 KB |
Output is correct |
27 |
Correct |
100 ms |
65608 KB |
Output is correct |
28 |
Correct |
72 ms |
57240 KB |
Output is correct |
29 |
Correct |
77 ms |
56912 KB |
Output is correct |
30 |
Correct |
21 ms |
47196 KB |
Output is correct |
31 |
Correct |
22 ms |
47196 KB |
Output is correct |
32 |
Correct |
20 ms |
47208 KB |
Output is correct |
33 |
Correct |
20 ms |
47196 KB |
Output is correct |
34 |
Correct |
21 ms |
47452 KB |
Output is correct |
35 |
Correct |
21 ms |
47448 KB |
Output is correct |
36 |
Correct |
20 ms |
47192 KB |
Output is correct |
37 |
Correct |
21 ms |
47448 KB |
Output is correct |
38 |
Correct |
22 ms |
47192 KB |
Output is correct |
39 |
Correct |
21 ms |
47196 KB |
Output is correct |
40 |
Correct |
20 ms |
47452 KB |
Output is correct |
41 |
Correct |
21 ms |
47452 KB |
Output is correct |
42 |
Correct |
22 ms |
47192 KB |
Output is correct |
43 |
Correct |
20 ms |
47440 KB |
Output is correct |
44 |
Correct |
20 ms |
47452 KB |
Output is correct |
45 |
Correct |
21 ms |
47452 KB |
Output is correct |
46 |
Correct |
20 ms |
47452 KB |
Output is correct |
47 |
Correct |
21 ms |
47244 KB |
Output is correct |
48 |
Correct |
20 ms |
47196 KB |
Output is correct |
49 |
Correct |
25 ms |
47424 KB |
Output is correct |
50 |
Correct |
21 ms |
47452 KB |
Output is correct |
51 |
Correct |
21 ms |
47192 KB |
Output is correct |
52 |
Correct |
20 ms |
47452 KB |
Output is correct |
53 |
Correct |
20 ms |
47452 KB |
Output is correct |
54 |
Correct |
21 ms |
47216 KB |
Output is correct |
55 |
Correct |
21 ms |
47452 KB |
Output is correct |
56 |
Correct |
20 ms |
47196 KB |
Output is correct |
57 |
Correct |
20 ms |
47196 KB |
Output is correct |
58 |
Correct |
21 ms |
47192 KB |
Output is correct |
59 |
Correct |
25 ms |
47196 KB |
Output is correct |
60 |
Correct |
25 ms |
47196 KB |
Output is correct |
61 |
Correct |
20 ms |
47452 KB |
Output is correct |
62 |
Correct |
21 ms |
47452 KB |
Output is correct |
63 |
Correct |
22 ms |
47604 KB |
Output is correct |
64 |
Correct |
21 ms |
47448 KB |
Output is correct |
65 |
Correct |
23 ms |
47516 KB |
Output is correct |
66 |
Correct |
21 ms |
47452 KB |
Output is correct |
67 |
Correct |
21 ms |
47452 KB |
Output is correct |
68 |
Correct |
25 ms |
47644 KB |
Output is correct |
69 |
Correct |
22 ms |
47708 KB |
Output is correct |
70 |
Correct |
22 ms |
47444 KB |
Output is correct |
71 |
Correct |
21 ms |
47448 KB |
Output is correct |
72 |
Correct |
21 ms |
47448 KB |
Output is correct |
73 |
Correct |
22 ms |
47452 KB |
Output is correct |
74 |
Correct |
22 ms |
47452 KB |
Output is correct |
75 |
Correct |
22 ms |
47452 KB |
Output is correct |
76 |
Correct |
22 ms |
47452 KB |
Output is correct |
77 |
Correct |
21 ms |
47452 KB |
Output is correct |
78 |
Correct |
22 ms |
47556 KB |
Output is correct |
79 |
Correct |
21 ms |
47456 KB |
Output is correct |
80 |
Correct |
27 ms |
47452 KB |
Output is correct |
81 |
Correct |
22 ms |
47452 KB |
Output is correct |
82 |
Correct |
22 ms |
47708 KB |
Output is correct |
83 |
Correct |
22 ms |
47660 KB |
Output is correct |
84 |
Correct |
21 ms |
47592 KB |
Output is correct |
85 |
Correct |
20 ms |
47604 KB |
Output is correct |
86 |
Correct |
21 ms |
47452 KB |
Output is correct |
87 |
Correct |
22 ms |
47452 KB |
Output is correct |
88 |
Correct |
103 ms |
57976 KB |
Output is correct |
89 |
Correct |
104 ms |
58056 KB |
Output is correct |
90 |
Correct |
100 ms |
60972 KB |
Output is correct |
91 |
Correct |
55 ms |
53148 KB |
Output is correct |
92 |
Correct |
54 ms |
53064 KB |
Output is correct |
93 |
Correct |
62 ms |
57956 KB |
Output is correct |
94 |
Correct |
65 ms |
57908 KB |
Output is correct |
95 |
Correct |
166 ms |
60840 KB |
Output is correct |
96 |
Correct |
146 ms |
59332 KB |
Output is correct |
97 |
Correct |
149 ms |
59984 KB |
Output is correct |
98 |
Correct |
137 ms |
59988 KB |
Output is correct |
99 |
Correct |
82 ms |
59984 KB |
Output is correct |
100 |
Correct |
79 ms |
59988 KB |
Output is correct |
101 |
Correct |
55 ms |
53076 KB |
Output is correct |
102 |
Correct |
54 ms |
53136 KB |
Output is correct |
103 |
Correct |
60 ms |
57972 KB |
Output is correct |
104 |
Correct |
60 ms |
57932 KB |
Output is correct |
105 |
Correct |
165 ms |
60964 KB |
Output is correct |
106 |
Correct |
155 ms |
60912 KB |
Output is correct |
107 |
Correct |
169 ms |
65844 KB |
Output is correct |
108 |
Correct |
148 ms |
65792 KB |
Output is correct |
109 |
Correct |
83 ms |
57188 KB |
Output is correct |
110 |
Correct |
85 ms |
61012 KB |
Output is correct |
111 |
Correct |
103 ms |
60012 KB |
Output is correct |
112 |
Correct |
100 ms |
60052 KB |
Output is correct |