#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 300005;
ll n , m , au[300005] , av[300005] , aw[300005];
ll u , v , w , A;
vector<pair<ll, pair<ll , ll> > > adj[300005];
ll d1[300005] , dn[300005] , f[300005] , par[300005] , path[300005] , son[300005];
multiset<pair<ll , ll>> S;
vector<ll> B[300005] , T[300005];
void q(ll x){
f[x] = 1;
for(auto y : adj[x]){
//cout << "h";
auto it = S.find({dn[y.first] + y.second.first + d1[x] , y.second.second});
if(f[y.first]) S.erase(it);
else S.insert({dn[x] + y.second.first + d1[y.first] , y.second.second});
}
}
void dfs(int u , int p){
if(path[u]) son[u] = u;
else son[u] = son[p];
T[son[u]].emplace_back(u);
for(int v : B[u]) dfs(v , u);
}
main (){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i =0; i <m; ++i) cin >> au[i] >> av[i] >> aw[i];
for(int i = m - 1; ~i; --i){
u = au[i] , v = av[i] , w= aw[i];
adj[u].push_back({v , {w , A}});
adj[v].push_back({u , {w , A}});
A = max(A , w);
//cout << "j";
}
for(int i = 1; i <= n; ++i) d1[i] = dn[i] = 1e18;
d1[1] = 0;
dn[n] = 0;
priority_queue<pair<ll , ll> > pq;
pq.push({0 , 1});
while(pq.size()){
auto T = pq.top(); pq.pop();
u = T.second , w = -T.first;
if(f[u])continue;
f[u] = 1;
for(auto e : adj[u]){
v = e.first;
if(!f[v] && d1[v] > w + e.second.first){
par[v] = u;
d1[v] = w + e.second.first;
pq.push({-d1[v] , v});
}
}
//cout << "k";
}
for(int i = 1; i <= n; ++i)f[i] = 0;
//memset(f , 0 ,sizeof(f));
pq.push({0, n});
while(pq.size()){
auto T = pq.top(); pq.pop();
u = T.second , w = -T.first;
if(f[u])continue;
f[u] = 1;
for(auto e : adj[u]){
v = e.first;
if(!f[v] && dn[v] > w + e.second.first){
dn[v]= w + e.second.first;
pq.push({-dn[v] , v});
}
}
//cout << "l";
}
ll X = n;
while(1){
path[X] = 1;
if(X == 1) break;
X = par[X];
//cout << "n";
}
for(int i = 1; i <= n; ++i)B[par[i]].emplace_back(i);
dfs(1 , 0);
for(int i = 1; i <= n; ++i) f[i] =0;
ll s = n;
ll ans = d1[n];
//cout << "ka";
ll k;
while(1){
//cout << "ha";
if(s == 1)break;
for(ll v : T[s]) q(v);
s = par[s];
k = S.begin()->first + S.begin()->second;
auto i = S.begin();
++i;
if(i != S.end()) k =min(k , i->first);
ans = max(ans , k);
}
cout << ans;
}
Compilation message
Aesthetic.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main (){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21452 KB |
Output is correct |
2 |
Correct |
12 ms |
21452 KB |
Output is correct |
3 |
Correct |
12 ms |
21452 KB |
Output is correct |
4 |
Correct |
12 ms |
21452 KB |
Output is correct |
5 |
Correct |
12 ms |
21452 KB |
Output is correct |
6 |
Correct |
13 ms |
21452 KB |
Output is correct |
7 |
Correct |
12 ms |
21452 KB |
Output is correct |
8 |
Correct |
12 ms |
21428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21452 KB |
Output is correct |
2 |
Correct |
12 ms |
21452 KB |
Output is correct |
3 |
Correct |
12 ms |
21452 KB |
Output is correct |
4 |
Correct |
12 ms |
21452 KB |
Output is correct |
5 |
Correct |
12 ms |
21452 KB |
Output is correct |
6 |
Correct |
13 ms |
21452 KB |
Output is correct |
7 |
Correct |
12 ms |
21452 KB |
Output is correct |
8 |
Correct |
12 ms |
21428 KB |
Output is correct |
9 |
Correct |
17 ms |
21776 KB |
Output is correct |
10 |
Correct |
13 ms |
21776 KB |
Output is correct |
11 |
Correct |
14 ms |
21716 KB |
Output is correct |
12 |
Correct |
16 ms |
21708 KB |
Output is correct |
13 |
Correct |
15 ms |
21776 KB |
Output is correct |
14 |
Correct |
14 ms |
21792 KB |
Output is correct |
15 |
Correct |
14 ms |
21724 KB |
Output is correct |
16 |
Correct |
13 ms |
21708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
728 ms |
70200 KB |
Output is correct |
2 |
Correct |
715 ms |
69564 KB |
Output is correct |
3 |
Correct |
719 ms |
69736 KB |
Output is correct |
4 |
Correct |
731 ms |
70124 KB |
Output is correct |
5 |
Correct |
707 ms |
70212 KB |
Output is correct |
6 |
Correct |
751 ms |
71340 KB |
Output is correct |
7 |
Correct |
736 ms |
70744 KB |
Output is correct |
8 |
Correct |
724 ms |
71604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
779 ms |
71812 KB |
Output is correct |
2 |
Correct |
759 ms |
70556 KB |
Output is correct |
3 |
Correct |
747 ms |
68832 KB |
Output is correct |
4 |
Correct |
722 ms |
70912 KB |
Output is correct |
5 |
Correct |
726 ms |
70860 KB |
Output is correct |
6 |
Correct |
756 ms |
71560 KB |
Output is correct |
7 |
Correct |
730 ms |
70636 KB |
Output is correct |
8 |
Correct |
707 ms |
70904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
565 ms |
64948 KB |
Output is correct |
2 |
Correct |
297 ms |
68912 KB |
Output is correct |
3 |
Correct |
325 ms |
59824 KB |
Output is correct |
4 |
Correct |
278 ms |
58676 KB |
Output is correct |
5 |
Correct |
297 ms |
58436 KB |
Output is correct |
6 |
Correct |
275 ms |
59720 KB |
Output is correct |
7 |
Correct |
270 ms |
58068 KB |
Output is correct |
8 |
Correct |
270 ms |
58604 KB |
Output is correct |
9 |
Correct |
249 ms |
57504 KB |
Output is correct |
10 |
Correct |
293 ms |
60640 KB |
Output is correct |
11 |
Correct |
268 ms |
58260 KB |
Output is correct |
12 |
Correct |
688 ms |
65676 KB |
Output is correct |
13 |
Correct |
260 ms |
58532 KB |
Output is correct |
14 |
Correct |
237 ms |
80856 KB |
Output is correct |
15 |
Correct |
183 ms |
70828 KB |
Output is correct |
16 |
Correct |
557 ms |
64732 KB |
Output is correct |
17 |
Correct |
565 ms |
64660 KB |
Output is correct |
18 |
Correct |
501 ms |
63100 KB |
Output is correct |
19 |
Correct |
322 ms |
69060 KB |
Output is correct |
20 |
Correct |
300 ms |
69108 KB |
Output is correct |
21 |
Correct |
301 ms |
68956 KB |
Output is correct |
22 |
Correct |
297 ms |
68980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
565 ms |
64948 KB |
Output is correct |
2 |
Correct |
297 ms |
68912 KB |
Output is correct |
3 |
Correct |
325 ms |
59824 KB |
Output is correct |
4 |
Correct |
278 ms |
58676 KB |
Output is correct |
5 |
Correct |
297 ms |
58436 KB |
Output is correct |
6 |
Correct |
275 ms |
59720 KB |
Output is correct |
7 |
Correct |
270 ms |
58068 KB |
Output is correct |
8 |
Correct |
270 ms |
58604 KB |
Output is correct |
9 |
Correct |
249 ms |
57504 KB |
Output is correct |
10 |
Correct |
293 ms |
60640 KB |
Output is correct |
11 |
Correct |
268 ms |
58260 KB |
Output is correct |
12 |
Correct |
688 ms |
65676 KB |
Output is correct |
13 |
Correct |
260 ms |
58532 KB |
Output is correct |
14 |
Correct |
237 ms |
80856 KB |
Output is correct |
15 |
Correct |
183 ms |
70828 KB |
Output is correct |
16 |
Correct |
557 ms |
64732 KB |
Output is correct |
17 |
Correct |
565 ms |
64660 KB |
Output is correct |
18 |
Correct |
501 ms |
63100 KB |
Output is correct |
19 |
Correct |
322 ms |
69060 KB |
Output is correct |
20 |
Correct |
300 ms |
69108 KB |
Output is correct |
21 |
Correct |
301 ms |
68956 KB |
Output is correct |
22 |
Correct |
297 ms |
68980 KB |
Output is correct |
23 |
Correct |
717 ms |
66060 KB |
Output is correct |
24 |
Correct |
399 ms |
69180 KB |
Output is correct |
25 |
Correct |
386 ms |
58876 KB |
Output is correct |
26 |
Correct |
376 ms |
58444 KB |
Output is correct |
27 |
Correct |
350 ms |
58312 KB |
Output is correct |
28 |
Correct |
453 ms |
60036 KB |
Output is correct |
29 |
Correct |
412 ms |
58648 KB |
Output is correct |
30 |
Correct |
394 ms |
59432 KB |
Output is correct |
31 |
Correct |
413 ms |
59848 KB |
Output is correct |
32 |
Correct |
404 ms |
57776 KB |
Output is correct |
33 |
Correct |
437 ms |
59272 KB |
Output is correct |
34 |
Correct |
778 ms |
65916 KB |
Output is correct |
35 |
Correct |
465 ms |
58412 KB |
Output is correct |
36 |
Correct |
279 ms |
83716 KB |
Output is correct |
37 |
Correct |
324 ms |
83684 KB |
Output is correct |
38 |
Correct |
749 ms |
65536 KB |
Output is correct |
39 |
Correct |
725 ms |
65212 KB |
Output is correct |
40 |
Correct |
802 ms |
66244 KB |
Output is correct |
41 |
Correct |
383 ms |
69188 KB |
Output is correct |
42 |
Correct |
358 ms |
69152 KB |
Output is correct |
43 |
Correct |
357 ms |
69280 KB |
Output is correct |
44 |
Correct |
360 ms |
69224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21452 KB |
Output is correct |
2 |
Correct |
12 ms |
21452 KB |
Output is correct |
3 |
Correct |
12 ms |
21452 KB |
Output is correct |
4 |
Correct |
12 ms |
21452 KB |
Output is correct |
5 |
Correct |
12 ms |
21452 KB |
Output is correct |
6 |
Correct |
13 ms |
21452 KB |
Output is correct |
7 |
Correct |
12 ms |
21452 KB |
Output is correct |
8 |
Correct |
12 ms |
21428 KB |
Output is correct |
9 |
Correct |
17 ms |
21776 KB |
Output is correct |
10 |
Correct |
13 ms |
21776 KB |
Output is correct |
11 |
Correct |
14 ms |
21716 KB |
Output is correct |
12 |
Correct |
16 ms |
21708 KB |
Output is correct |
13 |
Correct |
15 ms |
21776 KB |
Output is correct |
14 |
Correct |
14 ms |
21792 KB |
Output is correct |
15 |
Correct |
14 ms |
21724 KB |
Output is correct |
16 |
Correct |
13 ms |
21708 KB |
Output is correct |
17 |
Correct |
728 ms |
70200 KB |
Output is correct |
18 |
Correct |
715 ms |
69564 KB |
Output is correct |
19 |
Correct |
719 ms |
69736 KB |
Output is correct |
20 |
Correct |
731 ms |
70124 KB |
Output is correct |
21 |
Correct |
707 ms |
70212 KB |
Output is correct |
22 |
Correct |
751 ms |
71340 KB |
Output is correct |
23 |
Correct |
736 ms |
70744 KB |
Output is correct |
24 |
Correct |
724 ms |
71604 KB |
Output is correct |
25 |
Correct |
779 ms |
71812 KB |
Output is correct |
26 |
Correct |
759 ms |
70556 KB |
Output is correct |
27 |
Correct |
747 ms |
68832 KB |
Output is correct |
28 |
Correct |
722 ms |
70912 KB |
Output is correct |
29 |
Correct |
726 ms |
70860 KB |
Output is correct |
30 |
Correct |
756 ms |
71560 KB |
Output is correct |
31 |
Correct |
730 ms |
70636 KB |
Output is correct |
32 |
Correct |
707 ms |
70904 KB |
Output is correct |
33 |
Correct |
565 ms |
64948 KB |
Output is correct |
34 |
Correct |
297 ms |
68912 KB |
Output is correct |
35 |
Correct |
325 ms |
59824 KB |
Output is correct |
36 |
Correct |
278 ms |
58676 KB |
Output is correct |
37 |
Correct |
297 ms |
58436 KB |
Output is correct |
38 |
Correct |
275 ms |
59720 KB |
Output is correct |
39 |
Correct |
270 ms |
58068 KB |
Output is correct |
40 |
Correct |
270 ms |
58604 KB |
Output is correct |
41 |
Correct |
249 ms |
57504 KB |
Output is correct |
42 |
Correct |
293 ms |
60640 KB |
Output is correct |
43 |
Correct |
268 ms |
58260 KB |
Output is correct |
44 |
Correct |
688 ms |
65676 KB |
Output is correct |
45 |
Correct |
260 ms |
58532 KB |
Output is correct |
46 |
Correct |
237 ms |
80856 KB |
Output is correct |
47 |
Correct |
183 ms |
70828 KB |
Output is correct |
48 |
Correct |
557 ms |
64732 KB |
Output is correct |
49 |
Correct |
565 ms |
64660 KB |
Output is correct |
50 |
Correct |
501 ms |
63100 KB |
Output is correct |
51 |
Correct |
322 ms |
69060 KB |
Output is correct |
52 |
Correct |
300 ms |
69108 KB |
Output is correct |
53 |
Correct |
301 ms |
68956 KB |
Output is correct |
54 |
Correct |
297 ms |
68980 KB |
Output is correct |
55 |
Correct |
717 ms |
66060 KB |
Output is correct |
56 |
Correct |
399 ms |
69180 KB |
Output is correct |
57 |
Correct |
386 ms |
58876 KB |
Output is correct |
58 |
Correct |
376 ms |
58444 KB |
Output is correct |
59 |
Correct |
350 ms |
58312 KB |
Output is correct |
60 |
Correct |
453 ms |
60036 KB |
Output is correct |
61 |
Correct |
412 ms |
58648 KB |
Output is correct |
62 |
Correct |
394 ms |
59432 KB |
Output is correct |
63 |
Correct |
413 ms |
59848 KB |
Output is correct |
64 |
Correct |
404 ms |
57776 KB |
Output is correct |
65 |
Correct |
437 ms |
59272 KB |
Output is correct |
66 |
Correct |
778 ms |
65916 KB |
Output is correct |
67 |
Correct |
465 ms |
58412 KB |
Output is correct |
68 |
Correct |
279 ms |
83716 KB |
Output is correct |
69 |
Correct |
324 ms |
83684 KB |
Output is correct |
70 |
Correct |
749 ms |
65536 KB |
Output is correct |
71 |
Correct |
725 ms |
65212 KB |
Output is correct |
72 |
Correct |
802 ms |
66244 KB |
Output is correct |
73 |
Correct |
383 ms |
69188 KB |
Output is correct |
74 |
Correct |
358 ms |
69152 KB |
Output is correct |
75 |
Correct |
357 ms |
69280 KB |
Output is correct |
76 |
Correct |
360 ms |
69224 KB |
Output is correct |
77 |
Correct |
851 ms |
66600 KB |
Output is correct |
78 |
Correct |
389 ms |
69152 KB |
Output is correct |
79 |
Correct |
470 ms |
59176 KB |
Output is correct |
80 |
Correct |
451 ms |
57900 KB |
Output is correct |
81 |
Correct |
435 ms |
59244 KB |
Output is correct |
82 |
Correct |
475 ms |
59000 KB |
Output is correct |
83 |
Correct |
453 ms |
58356 KB |
Output is correct |
84 |
Correct |
456 ms |
58444 KB |
Output is correct |
85 |
Correct |
427 ms |
59424 KB |
Output is correct |
86 |
Correct |
466 ms |
59164 KB |
Output is correct |
87 |
Correct |
430 ms |
58352 KB |
Output is correct |
88 |
Correct |
692 ms |
65768 KB |
Output is correct |
89 |
Correct |
471 ms |
58860 KB |
Output is correct |
90 |
Correct |
297 ms |
83684 KB |
Output is correct |
91 |
Correct |
344 ms |
83656 KB |
Output is correct |
92 |
Runtime error |
824 ms |
134636 KB |
Execution killed with signal 6 |
93 |
Halted |
0 ms |
0 KB |
- |