#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n , m ,A, au[300002] , av[300002] , aw[300002];
vector<pair<ll, pair<ll , ll> > > adj[300002];
ll d1[300002] , dn[300002] , f[300002] , par[300002] , path[300002] , son[300002];
multiset<pair<ll , ll>> S;
vector<ll> B[300002] , T[300002];
void q(ll x){
f[x] = 1;
for(auto j : adj[x]){
//cout << "h";
ll y = j.first , l = j.second.first;
auto it = S.find({dn[y] + l + d1[x] , j.second.second});
if(f[y]==1) S.erase(it);
if(f[y] == 0) S.insert({dn[x] + l + d1[y] , j.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){
ll u = au[i] , v = av[i] , w= aw[i];
if(u != v){
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()){
ll u = pq.top().second;
pq.pop();
if(f[u])continue;
f[u] = 1;
for(auto e : adj[u]){
ll v = e.first , l = e.second.first;
if(!f[v] && d1[v] > d1[u] + l){
par[v] = u;
d1[v] = d1[u] + l;
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()){
ll u = pq.top().second;
pq.pop();
if(f[u])continue;
f[u] = 1;
for(auto e : adj[u]){
ll v = e.first , l = e.second.first;
if(!f[v] && dn[v] > dn[u] + l){
dn[v]= dn[u] + l;
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";
while(1){
//cout << "ha";
if(s == 1)break;
for(ll v : T[s]) q(v);
s = par[s];
ll 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<<endl;
}
Compilation message
Aesthetic.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main (){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
21452 KB |
Output is correct |
2 |
Correct |
12 ms |
21484 KB |
Output is correct |
3 |
Correct |
12 ms |
21452 KB |
Output is correct |
4 |
Correct |
12 ms |
21452 KB |
Output is correct |
5 |
Correct |
11 ms |
21452 KB |
Output is correct |
6 |
Correct |
12 ms |
21452 KB |
Output is correct |
7 |
Correct |
12 ms |
21528 KB |
Output is correct |
8 |
Correct |
13 ms |
21516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
21452 KB |
Output is correct |
2 |
Correct |
12 ms |
21484 KB |
Output is correct |
3 |
Correct |
12 ms |
21452 KB |
Output is correct |
4 |
Correct |
12 ms |
21452 KB |
Output is correct |
5 |
Correct |
11 ms |
21452 KB |
Output is correct |
6 |
Correct |
12 ms |
21452 KB |
Output is correct |
7 |
Correct |
12 ms |
21528 KB |
Output is correct |
8 |
Correct |
13 ms |
21516 KB |
Output is correct |
9 |
Correct |
14 ms |
21836 KB |
Output is correct |
10 |
Correct |
16 ms |
21776 KB |
Output is correct |
11 |
Correct |
14 ms |
21708 KB |
Output is correct |
12 |
Correct |
14 ms |
21808 KB |
Output is correct |
13 |
Correct |
13 ms |
21708 KB |
Output is correct |
14 |
Correct |
13 ms |
21716 KB |
Output is correct |
15 |
Correct |
13 ms |
21780 KB |
Output is correct |
16 |
Correct |
14 ms |
21800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
752 ms |
70104 KB |
Output is correct |
2 |
Correct |
794 ms |
69660 KB |
Output is correct |
3 |
Correct |
710 ms |
69848 KB |
Output is correct |
4 |
Correct |
706 ms |
69912 KB |
Output is correct |
5 |
Correct |
723 ms |
70188 KB |
Output is correct |
6 |
Correct |
728 ms |
71396 KB |
Output is correct |
7 |
Correct |
742 ms |
70812 KB |
Output is correct |
8 |
Correct |
727 ms |
71444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
733 ms |
71672 KB |
Output is correct |
2 |
Correct |
728 ms |
70556 KB |
Output is correct |
3 |
Correct |
718 ms |
68860 KB |
Output is correct |
4 |
Correct |
733 ms |
70876 KB |
Output is correct |
5 |
Correct |
763 ms |
70676 KB |
Output is correct |
6 |
Correct |
802 ms |
71476 KB |
Output is correct |
7 |
Correct |
709 ms |
70644 KB |
Output is correct |
8 |
Correct |
733 ms |
70864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
567 ms |
64916 KB |
Output is correct |
2 |
Correct |
304 ms |
68948 KB |
Output is correct |
3 |
Correct |
296 ms |
59848 KB |
Output is correct |
4 |
Correct |
271 ms |
58712 KB |
Output is correct |
5 |
Correct |
261 ms |
58348 KB |
Output is correct |
6 |
Correct |
290 ms |
59716 KB |
Output is correct |
7 |
Correct |
273 ms |
58120 KB |
Output is correct |
8 |
Correct |
271 ms |
58588 KB |
Output is correct |
9 |
Correct |
248 ms |
57512 KB |
Output is correct |
10 |
Correct |
303 ms |
60596 KB |
Output is correct |
11 |
Correct |
257 ms |
58200 KB |
Output is correct |
12 |
Correct |
636 ms |
65560 KB |
Output is correct |
13 |
Correct |
259 ms |
58428 KB |
Output is correct |
14 |
Correct |
247 ms |
80952 KB |
Output is correct |
15 |
Correct |
178 ms |
70696 KB |
Output is correct |
16 |
Correct |
492 ms |
64724 KB |
Output is correct |
17 |
Correct |
560 ms |
64824 KB |
Output is correct |
18 |
Correct |
465 ms |
63092 KB |
Output is correct |
19 |
Correct |
304 ms |
69076 KB |
Output is correct |
20 |
Correct |
300 ms |
68976 KB |
Output is correct |
21 |
Correct |
327 ms |
69084 KB |
Output is correct |
22 |
Correct |
300 ms |
68908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
567 ms |
64916 KB |
Output is correct |
2 |
Correct |
304 ms |
68948 KB |
Output is correct |
3 |
Correct |
296 ms |
59848 KB |
Output is correct |
4 |
Correct |
271 ms |
58712 KB |
Output is correct |
5 |
Correct |
261 ms |
58348 KB |
Output is correct |
6 |
Correct |
290 ms |
59716 KB |
Output is correct |
7 |
Correct |
273 ms |
58120 KB |
Output is correct |
8 |
Correct |
271 ms |
58588 KB |
Output is correct |
9 |
Correct |
248 ms |
57512 KB |
Output is correct |
10 |
Correct |
303 ms |
60596 KB |
Output is correct |
11 |
Correct |
257 ms |
58200 KB |
Output is correct |
12 |
Correct |
636 ms |
65560 KB |
Output is correct |
13 |
Correct |
259 ms |
58428 KB |
Output is correct |
14 |
Correct |
247 ms |
80952 KB |
Output is correct |
15 |
Correct |
178 ms |
70696 KB |
Output is correct |
16 |
Correct |
492 ms |
64724 KB |
Output is correct |
17 |
Correct |
560 ms |
64824 KB |
Output is correct |
18 |
Correct |
465 ms |
63092 KB |
Output is correct |
19 |
Correct |
304 ms |
69076 KB |
Output is correct |
20 |
Correct |
300 ms |
68976 KB |
Output is correct |
21 |
Correct |
327 ms |
69084 KB |
Output is correct |
22 |
Correct |
300 ms |
68908 KB |
Output is correct |
23 |
Correct |
687 ms |
66284 KB |
Output is correct |
24 |
Correct |
358 ms |
69220 KB |
Output is correct |
25 |
Correct |
384 ms |
58916 KB |
Output is correct |
26 |
Correct |
360 ms |
58488 KB |
Output is correct |
27 |
Correct |
344 ms |
58252 KB |
Output is correct |
28 |
Correct |
452 ms |
60036 KB |
Output is correct |
29 |
Correct |
391 ms |
58796 KB |
Output is correct |
30 |
Correct |
391 ms |
59136 KB |
Output is correct |
31 |
Correct |
425 ms |
59896 KB |
Output is correct |
32 |
Correct |
388 ms |
57720 KB |
Output is correct |
33 |
Correct |
419 ms |
59328 KB |
Output is correct |
34 |
Correct |
700 ms |
65944 KB |
Output is correct |
35 |
Correct |
413 ms |
58480 KB |
Output is correct |
36 |
Correct |
297 ms |
83732 KB |
Output is correct |
37 |
Correct |
303 ms |
83656 KB |
Output is correct |
38 |
Correct |
681 ms |
65504 KB |
Output is correct |
39 |
Correct |
716 ms |
65292 KB |
Output is correct |
40 |
Correct |
814 ms |
66268 KB |
Output is correct |
41 |
Correct |
365 ms |
69184 KB |
Output is correct |
42 |
Correct |
365 ms |
69228 KB |
Output is correct |
43 |
Correct |
364 ms |
69096 KB |
Output is correct |
44 |
Correct |
362 ms |
69204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
21452 KB |
Output is correct |
2 |
Correct |
12 ms |
21484 KB |
Output is correct |
3 |
Correct |
12 ms |
21452 KB |
Output is correct |
4 |
Correct |
12 ms |
21452 KB |
Output is correct |
5 |
Correct |
11 ms |
21452 KB |
Output is correct |
6 |
Correct |
12 ms |
21452 KB |
Output is correct |
7 |
Correct |
12 ms |
21528 KB |
Output is correct |
8 |
Correct |
13 ms |
21516 KB |
Output is correct |
9 |
Correct |
14 ms |
21836 KB |
Output is correct |
10 |
Correct |
16 ms |
21776 KB |
Output is correct |
11 |
Correct |
14 ms |
21708 KB |
Output is correct |
12 |
Correct |
14 ms |
21808 KB |
Output is correct |
13 |
Correct |
13 ms |
21708 KB |
Output is correct |
14 |
Correct |
13 ms |
21716 KB |
Output is correct |
15 |
Correct |
13 ms |
21780 KB |
Output is correct |
16 |
Correct |
14 ms |
21800 KB |
Output is correct |
17 |
Correct |
752 ms |
70104 KB |
Output is correct |
18 |
Correct |
794 ms |
69660 KB |
Output is correct |
19 |
Correct |
710 ms |
69848 KB |
Output is correct |
20 |
Correct |
706 ms |
69912 KB |
Output is correct |
21 |
Correct |
723 ms |
70188 KB |
Output is correct |
22 |
Correct |
728 ms |
71396 KB |
Output is correct |
23 |
Correct |
742 ms |
70812 KB |
Output is correct |
24 |
Correct |
727 ms |
71444 KB |
Output is correct |
25 |
Correct |
733 ms |
71672 KB |
Output is correct |
26 |
Correct |
728 ms |
70556 KB |
Output is correct |
27 |
Correct |
718 ms |
68860 KB |
Output is correct |
28 |
Correct |
733 ms |
70876 KB |
Output is correct |
29 |
Correct |
763 ms |
70676 KB |
Output is correct |
30 |
Correct |
802 ms |
71476 KB |
Output is correct |
31 |
Correct |
709 ms |
70644 KB |
Output is correct |
32 |
Correct |
733 ms |
70864 KB |
Output is correct |
33 |
Correct |
567 ms |
64916 KB |
Output is correct |
34 |
Correct |
304 ms |
68948 KB |
Output is correct |
35 |
Correct |
296 ms |
59848 KB |
Output is correct |
36 |
Correct |
271 ms |
58712 KB |
Output is correct |
37 |
Correct |
261 ms |
58348 KB |
Output is correct |
38 |
Correct |
290 ms |
59716 KB |
Output is correct |
39 |
Correct |
273 ms |
58120 KB |
Output is correct |
40 |
Correct |
271 ms |
58588 KB |
Output is correct |
41 |
Correct |
248 ms |
57512 KB |
Output is correct |
42 |
Correct |
303 ms |
60596 KB |
Output is correct |
43 |
Correct |
257 ms |
58200 KB |
Output is correct |
44 |
Correct |
636 ms |
65560 KB |
Output is correct |
45 |
Correct |
259 ms |
58428 KB |
Output is correct |
46 |
Correct |
247 ms |
80952 KB |
Output is correct |
47 |
Correct |
178 ms |
70696 KB |
Output is correct |
48 |
Correct |
492 ms |
64724 KB |
Output is correct |
49 |
Correct |
560 ms |
64824 KB |
Output is correct |
50 |
Correct |
465 ms |
63092 KB |
Output is correct |
51 |
Correct |
304 ms |
69076 KB |
Output is correct |
52 |
Correct |
300 ms |
68976 KB |
Output is correct |
53 |
Correct |
327 ms |
69084 KB |
Output is correct |
54 |
Correct |
300 ms |
68908 KB |
Output is correct |
55 |
Correct |
687 ms |
66284 KB |
Output is correct |
56 |
Correct |
358 ms |
69220 KB |
Output is correct |
57 |
Correct |
384 ms |
58916 KB |
Output is correct |
58 |
Correct |
360 ms |
58488 KB |
Output is correct |
59 |
Correct |
344 ms |
58252 KB |
Output is correct |
60 |
Correct |
452 ms |
60036 KB |
Output is correct |
61 |
Correct |
391 ms |
58796 KB |
Output is correct |
62 |
Correct |
391 ms |
59136 KB |
Output is correct |
63 |
Correct |
425 ms |
59896 KB |
Output is correct |
64 |
Correct |
388 ms |
57720 KB |
Output is correct |
65 |
Correct |
419 ms |
59328 KB |
Output is correct |
66 |
Correct |
700 ms |
65944 KB |
Output is correct |
67 |
Correct |
413 ms |
58480 KB |
Output is correct |
68 |
Correct |
297 ms |
83732 KB |
Output is correct |
69 |
Correct |
303 ms |
83656 KB |
Output is correct |
70 |
Correct |
681 ms |
65504 KB |
Output is correct |
71 |
Correct |
716 ms |
65292 KB |
Output is correct |
72 |
Correct |
814 ms |
66268 KB |
Output is correct |
73 |
Correct |
365 ms |
69184 KB |
Output is correct |
74 |
Correct |
365 ms |
69228 KB |
Output is correct |
75 |
Correct |
364 ms |
69096 KB |
Output is correct |
76 |
Correct |
362 ms |
69204 KB |
Output is correct |
77 |
Correct |
840 ms |
66720 KB |
Output is correct |
78 |
Correct |
364 ms |
69104 KB |
Output is correct |
79 |
Correct |
447 ms |
59232 KB |
Output is correct |
80 |
Correct |
446 ms |
57908 KB |
Output is correct |
81 |
Correct |
432 ms |
59184 KB |
Output is correct |
82 |
Correct |
484 ms |
58956 KB |
Output is correct |
83 |
Correct |
465 ms |
58316 KB |
Output is correct |
84 |
Correct |
474 ms |
58452 KB |
Output is correct |
85 |
Correct |
438 ms |
59672 KB |
Output is correct |
86 |
Correct |
451 ms |
59196 KB |
Output is correct |
87 |
Correct |
435 ms |
58312 KB |
Output is correct |
88 |
Correct |
628 ms |
65752 KB |
Output is correct |
89 |
Correct |
433 ms |
58944 KB |
Output is correct |
90 |
Correct |
310 ms |
83636 KB |
Output is correct |
91 |
Correct |
357 ms |
83712 KB |
Output is correct |
92 |
Correct |
839 ms |
66408 KB |
Output is correct |
93 |
Correct |
555 ms |
64688 KB |
Output is correct |
94 |
Correct |
580 ms |
64192 KB |
Output is correct |
95 |
Correct |
395 ms |
69248 KB |
Output is correct |
96 |
Correct |
380 ms |
69380 KB |
Output is correct |
97 |
Correct |
370 ms |
69060 KB |
Output is correct |
98 |
Correct |
373 ms |
69148 KB |
Output is correct |