#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
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;
while (!pq.empty())
{
auto top = pq.top();
pq.pop();
int node = top.second;
long long curr = -top.first;
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:35: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]
35 | for (int i = 0; i < g[node].size(); ++i)
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5468 KB |
Output is correct |
7 |
Correct |
56 ms |
20184 KB |
Output is correct |
8 |
Correct |
70 ms |
20076 KB |
Output is correct |
9 |
Correct |
61 ms |
20584 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 |
5212 KB |
Output is correct |
14 |
Correct |
40 ms |
16988 KB |
Output is correct |
15 |
Correct |
114 ms |
20940 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
67 ms |
20124 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
5168 KB |
Output is correct |
21 |
Correct |
2 ms |
5208 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
38 ms |
16960 KB |
Output is correct |
24 |
Correct |
121 ms |
20872 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
74 ms |
25712 KB |
Output is correct |
28 |
Correct |
54 ms |
17364 KB |
Output is correct |
29 |
Correct |
53 ms |
17068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4952 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 |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5168 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 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 |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4952 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 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 |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
5040 KB |
Output is correct |
24 |
Correct |
3 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 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 |
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 |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4952 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 |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5168 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 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 |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4952 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 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 |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
5040 KB |
Output is correct |
24 |
Correct |
3 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 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 |
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 |
5296 KB |
Output is correct |
36 |
Correct |
3 ms |
5212 KB |
Output is correct |
37 |
Correct |
2 ms |
5212 KB |
Output is correct |
38 |
Correct |
2 ms |
5212 KB |
Output is correct |
39 |
Correct |
4 ms |
5212 KB |
Output is correct |
40 |
Correct |
3 ms |
5468 KB |
Output is correct |
41 |
Correct |
3 ms |
5212 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
43 |
Correct |
3 ms |
5468 KB |
Output is correct |
44 |
Correct |
3 ms |
5268 KB |
Output is correct |
45 |
Correct |
3 ms |
5212 KB |
Output is correct |
46 |
Correct |
3 ms |
5208 KB |
Output is correct |
47 |
Correct |
3 ms |
5212 KB |
Output is correct |
48 |
Correct |
3 ms |
5212 KB |
Output is correct |
49 |
Correct |
2 ms |
5212 KB |
Output is correct |
50 |
Correct |
2 ms |
5212 KB |
Output is correct |
51 |
Correct |
4 ms |
5448 KB |
Output is correct |
52 |
Correct |
3 ms |
5212 KB |
Output is correct |
53 |
Correct |
4 ms |
5468 KB |
Output is correct |
54 |
Correct |
3 ms |
5468 KB |
Output is correct |
55 |
Correct |
5 ms |
5212 KB |
Output is correct |
56 |
Correct |
5 ms |
5180 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 |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5468 KB |
Output is correct |
7 |
Correct |
56 ms |
20184 KB |
Output is correct |
8 |
Correct |
70 ms |
20076 KB |
Output is correct |
9 |
Correct |
61 ms |
20584 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 |
5212 KB |
Output is correct |
14 |
Correct |
40 ms |
16988 KB |
Output is correct |
15 |
Correct |
114 ms |
20940 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
67 ms |
20124 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
5168 KB |
Output is correct |
21 |
Correct |
2 ms |
5208 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
38 ms |
16960 KB |
Output is correct |
24 |
Correct |
121 ms |
20872 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
74 ms |
25712 KB |
Output is correct |
28 |
Correct |
54 ms |
17364 KB |
Output is correct |
29 |
Correct |
53 ms |
17068 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 |
4952 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 |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
5168 KB |
Output is correct |
38 |
Correct |
3 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 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 |
4952 KB |
Output is correct |
43 |
Correct |
2 ms |
4952 KB |
Output is correct |
44 |
Correct |
2 ms |
4956 KB |
Output is correct |
45 |
Correct |
2 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 |
4956 KB |
Output is correct |
52 |
Correct |
2 ms |
5040 KB |
Output is correct |
53 |
Correct |
3 ms |
4956 KB |
Output is correct |
54 |
Correct |
2 ms |
4956 KB |
Output is correct |
55 |
Correct |
2 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 |
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 |
5296 KB |
Output is correct |
65 |
Correct |
3 ms |
5212 KB |
Output is correct |
66 |
Correct |
2 ms |
5212 KB |
Output is correct |
67 |
Correct |
2 ms |
5212 KB |
Output is correct |
68 |
Correct |
4 ms |
5212 KB |
Output is correct |
69 |
Correct |
3 ms |
5468 KB |
Output is correct |
70 |
Correct |
3 ms |
5212 KB |
Output is correct |
71 |
Correct |
2 ms |
5212 KB |
Output is correct |
72 |
Correct |
3 ms |
5468 KB |
Output is correct |
73 |
Correct |
3 ms |
5268 KB |
Output is correct |
74 |
Correct |
3 ms |
5212 KB |
Output is correct |
75 |
Correct |
3 ms |
5208 KB |
Output is correct |
76 |
Correct |
3 ms |
5212 KB |
Output is correct |
77 |
Correct |
3 ms |
5212 KB |
Output is correct |
78 |
Correct |
2 ms |
5212 KB |
Output is correct |
79 |
Correct |
2 ms |
5212 KB |
Output is correct |
80 |
Correct |
4 ms |
5448 KB |
Output is correct |
81 |
Correct |
3 ms |
5212 KB |
Output is correct |
82 |
Correct |
4 ms |
5468 KB |
Output is correct |
83 |
Correct |
3 ms |
5468 KB |
Output is correct |
84 |
Correct |
5 ms |
5212 KB |
Output is correct |
85 |
Correct |
5 ms |
5180 KB |
Output is correct |
86 |
Correct |
3 ms |
5176 KB |
Output is correct |
87 |
Correct |
3 ms |
5212 KB |
Output is correct |
88 |
Correct |
85 ms |
19532 KB |
Output is correct |
89 |
Correct |
81 ms |
19508 KB |
Output is correct |
90 |
Correct |
80 ms |
22316 KB |
Output is correct |
91 |
Correct |
41 ms |
13908 KB |
Output is correct |
92 |
Correct |
44 ms |
13904 KB |
Output is correct |
93 |
Correct |
40 ms |
17492 KB |
Output is correct |
94 |
Correct |
38 ms |
17488 KB |
Output is correct |
95 |
Correct |
142 ms |
22324 KB |
Output is correct |
96 |
Correct |
128 ms |
20640 KB |
Output is correct |
97 |
Correct |
124 ms |
21292 KB |
Output is correct |
98 |
Correct |
106 ms |
21300 KB |
Output is correct |
99 |
Correct |
65 ms |
21328 KB |
Output is correct |
100 |
Correct |
62 ms |
21328 KB |
Output is correct |
101 |
Correct |
41 ms |
13904 KB |
Output is correct |
102 |
Correct |
42 ms |
13908 KB |
Output is correct |
103 |
Correct |
38 ms |
17500 KB |
Output is correct |
104 |
Correct |
38 ms |
17500 KB |
Output is correct |
105 |
Correct |
134 ms |
22312 KB |
Output is correct |
106 |
Correct |
138 ms |
22312 KB |
Output is correct |
107 |
Correct |
138 ms |
27036 KB |
Output is correct |
108 |
Correct |
134 ms |
26984 KB |
Output is correct |
109 |
Execution timed out |
2069 ms |
15804 KB |
Time limit exceeded |
110 |
Halted |
0 ms |
0 KB |
- |