#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e5 + 2;
const ll linf = 1e18;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> u(m), v(m), w(m), suff(m);
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
cin >> u[i] >> v[i] >> w[i];
u[i] -= 1; v[i] -= 1;
g[u[i]].push_back({v[i], i});
g[v[i]].push_back({u[i], i});
}
for (int i = m - 2; i >= 0; i--) suff[i] = max(suff[i + 1], w[i + 1]);
function<vector<ll>(int)> Dijk = [&] (int s) {
vector<ll> dist(n, linf);
priority_queue<pair<ll, int>> q;
q.push({0, s});
while (!q.empty()) {
auto s = q.top(); q.pop();
s.first *= -1;
if (dist[s.second] <= s.first) continue;
dist[s.second] = s.first;
for (auto u : g[s.second]) {
if (dist[u.first] == linf) q.push({-s.first - w[u.second], u.first});
}
}
return dist;
};
vector<ll> a = Dijk(0);
vector<ll> b = Dijk(n - 1);
ll l = b[0], r = b[0] + suff[0];
auto Greater = [&] (ll x) {
int is = 0;
vector<int> dep(n, -1), mn(n);
int tsz = 0;
function<void(int, int)> Dfs = [&] (int s, int e) {
dep[s] = mn[s] = tsz++;
for (auto u : g[s]) {
if (u.first == e) continue;
ll y = min(a[s] + b[u.first], a[u.first] + b[s]) + w[u.second];
if (y > x) continue;
if (dep[u.first] == -1) {
Dfs(u.first, s);
smin(mn[s], mn[u.first]);
if (mn[u.first] > dep[s] && y + suff[u.second] > x && dep[n - 1] >= mn[u.first]) {
is = 1;
break;
}
}
else smin(mn[s], dep[u.first]);
}
};
Dfs(0, -1);
return is;
};
while (l < r) {
ll mid = l + r >> 1;
if (Greater(mid)) l = mid + 1;
else r = mid;
}
cout << l << en;
return 0;
}
Compilation message
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:69:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
69 | ll mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
424 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
369 ms |
36536 KB |
Output is correct |
2 |
Correct |
360 ms |
36816 KB |
Output is correct |
3 |
Correct |
378 ms |
36392 KB |
Output is correct |
4 |
Correct |
371 ms |
36500 KB |
Output is correct |
5 |
Correct |
382 ms |
36716 KB |
Output is correct |
6 |
Correct |
386 ms |
37424 KB |
Output is correct |
7 |
Correct |
388 ms |
37164 KB |
Output is correct |
8 |
Correct |
384 ms |
37476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
408 ms |
37404 KB |
Output is correct |
2 |
Correct |
383 ms |
36848 KB |
Output is correct |
3 |
Correct |
374 ms |
36772 KB |
Output is correct |
4 |
Correct |
388 ms |
37340 KB |
Output is correct |
5 |
Correct |
373 ms |
36600 KB |
Output is correct |
6 |
Correct |
355 ms |
36728 KB |
Output is correct |
7 |
Correct |
375 ms |
36768 KB |
Output is correct |
8 |
Correct |
402 ms |
37044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
321 ms |
30924 KB |
Output is correct |
2 |
Correct |
155 ms |
30600 KB |
Output is correct |
3 |
Correct |
226 ms |
31484 KB |
Output is correct |
4 |
Correct |
230 ms |
31568 KB |
Output is correct |
5 |
Correct |
239 ms |
31480 KB |
Output is correct |
6 |
Correct |
237 ms |
31656 KB |
Output is correct |
7 |
Correct |
229 ms |
31632 KB |
Output is correct |
8 |
Correct |
235 ms |
31756 KB |
Output is correct |
9 |
Correct |
242 ms |
31448 KB |
Output is correct |
10 |
Correct |
237 ms |
31756 KB |
Output is correct |
11 |
Correct |
245 ms |
31652 KB |
Output is correct |
12 |
Correct |
332 ms |
31000 KB |
Output is correct |
13 |
Correct |
244 ms |
31692 KB |
Output is correct |
14 |
Correct |
108 ms |
39128 KB |
Output is correct |
15 |
Correct |
120 ms |
39076 KB |
Output is correct |
16 |
Correct |
348 ms |
30908 KB |
Output is correct |
17 |
Correct |
367 ms |
30104 KB |
Output is correct |
18 |
Correct |
332 ms |
30740 KB |
Output is correct |
19 |
Correct |
150 ms |
30668 KB |
Output is correct |
20 |
Correct |
161 ms |
30804 KB |
Output is correct |
21 |
Correct |
155 ms |
30716 KB |
Output is correct |
22 |
Correct |
152 ms |
30672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
321 ms |
30924 KB |
Output is correct |
2 |
Correct |
155 ms |
30600 KB |
Output is correct |
3 |
Correct |
226 ms |
31484 KB |
Output is correct |
4 |
Correct |
230 ms |
31568 KB |
Output is correct |
5 |
Correct |
239 ms |
31480 KB |
Output is correct |
6 |
Correct |
237 ms |
31656 KB |
Output is correct |
7 |
Correct |
229 ms |
31632 KB |
Output is correct |
8 |
Correct |
235 ms |
31756 KB |
Output is correct |
9 |
Correct |
242 ms |
31448 KB |
Output is correct |
10 |
Correct |
237 ms |
31756 KB |
Output is correct |
11 |
Correct |
245 ms |
31652 KB |
Output is correct |
12 |
Correct |
332 ms |
31000 KB |
Output is correct |
13 |
Correct |
244 ms |
31692 KB |
Output is correct |
14 |
Correct |
108 ms |
39128 KB |
Output is correct |
15 |
Correct |
120 ms |
39076 KB |
Output is correct |
16 |
Correct |
348 ms |
30908 KB |
Output is correct |
17 |
Correct |
367 ms |
30104 KB |
Output is correct |
18 |
Correct |
332 ms |
30740 KB |
Output is correct |
19 |
Correct |
150 ms |
30668 KB |
Output is correct |
20 |
Correct |
161 ms |
30804 KB |
Output is correct |
21 |
Correct |
155 ms |
30716 KB |
Output is correct |
22 |
Correct |
152 ms |
30672 KB |
Output is correct |
23 |
Correct |
390 ms |
31164 KB |
Output is correct |
24 |
Correct |
203 ms |
30824 KB |
Output is correct |
25 |
Correct |
227 ms |
26192 KB |
Output is correct |
26 |
Correct |
226 ms |
25068 KB |
Output is correct |
27 |
Correct |
230 ms |
25060 KB |
Output is correct |
28 |
Correct |
234 ms |
26412 KB |
Output is correct |
29 |
Correct |
235 ms |
25132 KB |
Output is correct |
30 |
Correct |
251 ms |
25804 KB |
Output is correct |
31 |
Correct |
247 ms |
25764 KB |
Output is correct |
32 |
Correct |
246 ms |
25324 KB |
Output is correct |
33 |
Correct |
227 ms |
26172 KB |
Output is correct |
34 |
Correct |
361 ms |
30832 KB |
Output is correct |
35 |
Correct |
237 ms |
25696 KB |
Output is correct |
36 |
Correct |
148 ms |
40348 KB |
Output is correct |
37 |
Correct |
150 ms |
41144 KB |
Output is correct |
38 |
Correct |
375 ms |
30804 KB |
Output is correct |
39 |
Correct |
366 ms |
30476 KB |
Output is correct |
40 |
Correct |
360 ms |
31276 KB |
Output is correct |
41 |
Correct |
206 ms |
30848 KB |
Output is correct |
42 |
Correct |
203 ms |
30816 KB |
Output is correct |
43 |
Correct |
204 ms |
30904 KB |
Output is correct |
44 |
Correct |
209 ms |
30908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
424 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
369 ms |
36536 KB |
Output is correct |
18 |
Correct |
360 ms |
36816 KB |
Output is correct |
19 |
Correct |
378 ms |
36392 KB |
Output is correct |
20 |
Correct |
371 ms |
36500 KB |
Output is correct |
21 |
Correct |
382 ms |
36716 KB |
Output is correct |
22 |
Correct |
386 ms |
37424 KB |
Output is correct |
23 |
Correct |
388 ms |
37164 KB |
Output is correct |
24 |
Correct |
384 ms |
37476 KB |
Output is correct |
25 |
Correct |
408 ms |
37404 KB |
Output is correct |
26 |
Correct |
383 ms |
36848 KB |
Output is correct |
27 |
Correct |
374 ms |
36772 KB |
Output is correct |
28 |
Correct |
388 ms |
37340 KB |
Output is correct |
29 |
Correct |
373 ms |
36600 KB |
Output is correct |
30 |
Correct |
355 ms |
36728 KB |
Output is correct |
31 |
Correct |
375 ms |
36768 KB |
Output is correct |
32 |
Correct |
402 ms |
37044 KB |
Output is correct |
33 |
Correct |
321 ms |
30924 KB |
Output is correct |
34 |
Correct |
155 ms |
30600 KB |
Output is correct |
35 |
Correct |
226 ms |
31484 KB |
Output is correct |
36 |
Correct |
230 ms |
31568 KB |
Output is correct |
37 |
Correct |
239 ms |
31480 KB |
Output is correct |
38 |
Correct |
237 ms |
31656 KB |
Output is correct |
39 |
Correct |
229 ms |
31632 KB |
Output is correct |
40 |
Correct |
235 ms |
31756 KB |
Output is correct |
41 |
Correct |
242 ms |
31448 KB |
Output is correct |
42 |
Correct |
237 ms |
31756 KB |
Output is correct |
43 |
Correct |
245 ms |
31652 KB |
Output is correct |
44 |
Correct |
332 ms |
31000 KB |
Output is correct |
45 |
Correct |
244 ms |
31692 KB |
Output is correct |
46 |
Correct |
108 ms |
39128 KB |
Output is correct |
47 |
Correct |
120 ms |
39076 KB |
Output is correct |
48 |
Correct |
348 ms |
30908 KB |
Output is correct |
49 |
Correct |
367 ms |
30104 KB |
Output is correct |
50 |
Correct |
332 ms |
30740 KB |
Output is correct |
51 |
Correct |
150 ms |
30668 KB |
Output is correct |
52 |
Correct |
161 ms |
30804 KB |
Output is correct |
53 |
Correct |
155 ms |
30716 KB |
Output is correct |
54 |
Correct |
152 ms |
30672 KB |
Output is correct |
55 |
Correct |
390 ms |
31164 KB |
Output is correct |
56 |
Correct |
203 ms |
30824 KB |
Output is correct |
57 |
Correct |
227 ms |
26192 KB |
Output is correct |
58 |
Correct |
226 ms |
25068 KB |
Output is correct |
59 |
Correct |
230 ms |
25060 KB |
Output is correct |
60 |
Correct |
234 ms |
26412 KB |
Output is correct |
61 |
Correct |
235 ms |
25132 KB |
Output is correct |
62 |
Correct |
251 ms |
25804 KB |
Output is correct |
63 |
Correct |
247 ms |
25764 KB |
Output is correct |
64 |
Correct |
246 ms |
25324 KB |
Output is correct |
65 |
Correct |
227 ms |
26172 KB |
Output is correct |
66 |
Correct |
361 ms |
30832 KB |
Output is correct |
67 |
Correct |
237 ms |
25696 KB |
Output is correct |
68 |
Correct |
148 ms |
40348 KB |
Output is correct |
69 |
Correct |
150 ms |
41144 KB |
Output is correct |
70 |
Correct |
375 ms |
30804 KB |
Output is correct |
71 |
Correct |
366 ms |
30476 KB |
Output is correct |
72 |
Correct |
360 ms |
31276 KB |
Output is correct |
73 |
Correct |
206 ms |
30848 KB |
Output is correct |
74 |
Correct |
203 ms |
30816 KB |
Output is correct |
75 |
Correct |
204 ms |
30904 KB |
Output is correct |
76 |
Correct |
209 ms |
30908 KB |
Output is correct |
77 |
Correct |
394 ms |
33716 KB |
Output is correct |
78 |
Correct |
487 ms |
33244 KB |
Output is correct |
79 |
Correct |
351 ms |
34112 KB |
Output is correct |
80 |
Correct |
352 ms |
33864 KB |
Output is correct |
81 |
Correct |
323 ms |
33820 KB |
Output is correct |
82 |
Correct |
311 ms |
33832 KB |
Output is correct |
83 |
Correct |
307 ms |
34056 KB |
Output is correct |
84 |
Correct |
316 ms |
34240 KB |
Output is correct |
85 |
Correct |
307 ms |
33840 KB |
Output is correct |
86 |
Correct |
321 ms |
33800 KB |
Output is correct |
87 |
Correct |
331 ms |
34044 KB |
Output is correct |
88 |
Correct |
378 ms |
33480 KB |
Output is correct |
89 |
Correct |
327 ms |
33968 KB |
Output is correct |
90 |
Correct |
265 ms |
41136 KB |
Output is correct |
91 |
Correct |
280 ms |
41872 KB |
Output is correct |
92 |
Correct |
377 ms |
33572 KB |
Output is correct |
93 |
Correct |
378 ms |
33168 KB |
Output is correct |
94 |
Correct |
368 ms |
32652 KB |
Output is correct |
95 |
Correct |
472 ms |
33196 KB |
Output is correct |
96 |
Correct |
485 ms |
33176 KB |
Output is correct |
97 |
Correct |
491 ms |
33168 KB |
Output is correct |
98 |
Correct |
495 ms |
33132 KB |
Output is correct |