#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 1;
ll n , m , au[N] , av[N] , aw[N];
ll u , v , w , A = 0;
vector<pair<ll, pair<ll , ll> > > adj[N];
ll d1[N] , dn[N] , f[N] , par[N] , path[N] , son[N];
priority_queue<pair<ll , ll> > pq;
multiset<pair<ll , ll>> S;
vector<ll> B[N] , T[N];
void q(int 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;
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(d1[v] > w + e.second.first){
par[v] = u;
d1[v] = w + e.second.first;
pq.push({-d1[v] , v});
}
}
//cout << "k";
}
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(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);
memset(f , 0 ,sizeof(f));
u = n;
ll ans = d1[n];
//cout << "ka";
while(1){
//cout << "ha";
if(u == 1)break;
for(ll v : T[u]) q(v);
if(!S.size())continue;
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);
u = par[u];
}
cout << ans;
}
Compilation message
Aesthetic.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main (){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23840 KB |
Output is correct |
3 |
Correct |
13 ms |
23812 KB |
Output is correct |
4 |
Correct |
13 ms |
23884 KB |
Output is correct |
5 |
Correct |
13 ms |
23884 KB |
Output is correct |
6 |
Correct |
15 ms |
23860 KB |
Output is correct |
7 |
Correct |
13 ms |
23836 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23840 KB |
Output is correct |
3 |
Correct |
13 ms |
23812 KB |
Output is correct |
4 |
Correct |
13 ms |
23884 KB |
Output is correct |
5 |
Correct |
13 ms |
23884 KB |
Output is correct |
6 |
Correct |
15 ms |
23860 KB |
Output is correct |
7 |
Correct |
13 ms |
23836 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
15 ms |
24140 KB |
Output is correct |
10 |
Correct |
15 ms |
24140 KB |
Output is correct |
11 |
Correct |
15 ms |
24164 KB |
Output is correct |
12 |
Correct |
15 ms |
24164 KB |
Output is correct |
13 |
Correct |
15 ms |
24168 KB |
Output is correct |
14 |
Correct |
14 ms |
24140 KB |
Output is correct |
15 |
Correct |
14 ms |
24168 KB |
Output is correct |
16 |
Correct |
15 ms |
24168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
714 ms |
71660 KB |
Output is correct |
2 |
Correct |
726 ms |
71060 KB |
Output is correct |
3 |
Correct |
730 ms |
71288 KB |
Output is correct |
4 |
Correct |
684 ms |
71472 KB |
Output is correct |
5 |
Correct |
692 ms |
71784 KB |
Output is correct |
6 |
Correct |
721 ms |
72860 KB |
Output is correct |
7 |
Correct |
739 ms |
72396 KB |
Output is correct |
8 |
Correct |
742 ms |
72988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
753 ms |
73284 KB |
Output is correct |
2 |
Correct |
749 ms |
72100 KB |
Output is correct |
3 |
Correct |
731 ms |
70444 KB |
Output is correct |
4 |
Correct |
735 ms |
72444 KB |
Output is correct |
5 |
Correct |
714 ms |
72212 KB |
Output is correct |
6 |
Correct |
715 ms |
73200 KB |
Output is correct |
7 |
Correct |
729 ms |
72364 KB |
Output is correct |
8 |
Correct |
694 ms |
72372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
592 ms |
67096 KB |
Output is correct |
2 |
Correct |
309 ms |
73632 KB |
Output is correct |
3 |
Correct |
274 ms |
65356 KB |
Output is correct |
4 |
Correct |
283 ms |
64284 KB |
Output is correct |
5 |
Correct |
257 ms |
63892 KB |
Output is correct |
6 |
Correct |
287 ms |
65216 KB |
Output is correct |
7 |
Correct |
254 ms |
63548 KB |
Output is correct |
8 |
Correct |
254 ms |
64056 KB |
Output is correct |
9 |
Correct |
241 ms |
63096 KB |
Output is correct |
10 |
Correct |
308 ms |
66304 KB |
Output is correct |
11 |
Correct |
254 ms |
63760 KB |
Output is correct |
12 |
Correct |
625 ms |
70720 KB |
Output is correct |
13 |
Correct |
257 ms |
64092 KB |
Output is correct |
14 |
Correct |
248 ms |
86048 KB |
Output is correct |
15 |
Correct |
184 ms |
76012 KB |
Output is correct |
16 |
Correct |
494 ms |
69788 KB |
Output is correct |
17 |
Correct |
552 ms |
69784 KB |
Output is correct |
18 |
Correct |
453 ms |
68188 KB |
Output is correct |
19 |
Correct |
301 ms |
73832 KB |
Output is correct |
20 |
Correct |
300 ms |
73924 KB |
Output is correct |
21 |
Correct |
300 ms |
73836 KB |
Output is correct |
22 |
Correct |
298 ms |
73720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
592 ms |
67096 KB |
Output is correct |
2 |
Correct |
309 ms |
73632 KB |
Output is correct |
3 |
Correct |
274 ms |
65356 KB |
Output is correct |
4 |
Correct |
283 ms |
64284 KB |
Output is correct |
5 |
Correct |
257 ms |
63892 KB |
Output is correct |
6 |
Correct |
287 ms |
65216 KB |
Output is correct |
7 |
Correct |
254 ms |
63548 KB |
Output is correct |
8 |
Correct |
254 ms |
64056 KB |
Output is correct |
9 |
Correct |
241 ms |
63096 KB |
Output is correct |
10 |
Correct |
308 ms |
66304 KB |
Output is correct |
11 |
Correct |
254 ms |
63760 KB |
Output is correct |
12 |
Correct |
625 ms |
70720 KB |
Output is correct |
13 |
Correct |
257 ms |
64092 KB |
Output is correct |
14 |
Correct |
248 ms |
86048 KB |
Output is correct |
15 |
Correct |
184 ms |
76012 KB |
Output is correct |
16 |
Correct |
494 ms |
69788 KB |
Output is correct |
17 |
Correct |
552 ms |
69784 KB |
Output is correct |
18 |
Correct |
453 ms |
68188 KB |
Output is correct |
19 |
Correct |
301 ms |
73832 KB |
Output is correct |
20 |
Correct |
300 ms |
73924 KB |
Output is correct |
21 |
Correct |
300 ms |
73836 KB |
Output is correct |
22 |
Correct |
298 ms |
73720 KB |
Output is correct |
23 |
Correct |
697 ms |
71112 KB |
Output is correct |
24 |
Correct |
359 ms |
73924 KB |
Output is correct |
25 |
Correct |
387 ms |
64528 KB |
Output is correct |
26 |
Correct |
366 ms |
64132 KB |
Output is correct |
27 |
Correct |
347 ms |
63908 KB |
Output is correct |
28 |
Correct |
452 ms |
65640 KB |
Output is correct |
29 |
Correct |
402 ms |
64272 KB |
Output is correct |
30 |
Correct |
355 ms |
64780 KB |
Output is correct |
31 |
Correct |
430 ms |
65436 KB |
Output is correct |
32 |
Correct |
396 ms |
63344 KB |
Output is correct |
33 |
Correct |
430 ms |
65000 KB |
Output is correct |
34 |
Correct |
699 ms |
71068 KB |
Output is correct |
35 |
Correct |
428 ms |
64064 KB |
Output is correct |
36 |
Correct |
278 ms |
88420 KB |
Output is correct |
37 |
Correct |
302 ms |
89264 KB |
Output is correct |
38 |
Correct |
715 ms |
70496 KB |
Output is correct |
39 |
Correct |
725 ms |
70248 KB |
Output is correct |
40 |
Correct |
818 ms |
71312 KB |
Output is correct |
41 |
Correct |
405 ms |
73868 KB |
Output is correct |
42 |
Correct |
369 ms |
73912 KB |
Output is correct |
43 |
Correct |
371 ms |
74012 KB |
Output is correct |
44 |
Correct |
370 ms |
73936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23840 KB |
Output is correct |
3 |
Correct |
13 ms |
23812 KB |
Output is correct |
4 |
Correct |
13 ms |
23884 KB |
Output is correct |
5 |
Correct |
13 ms |
23884 KB |
Output is correct |
6 |
Correct |
15 ms |
23860 KB |
Output is correct |
7 |
Correct |
13 ms |
23836 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
15 ms |
24140 KB |
Output is correct |
10 |
Correct |
15 ms |
24140 KB |
Output is correct |
11 |
Correct |
15 ms |
24164 KB |
Output is correct |
12 |
Correct |
15 ms |
24164 KB |
Output is correct |
13 |
Correct |
15 ms |
24168 KB |
Output is correct |
14 |
Correct |
14 ms |
24140 KB |
Output is correct |
15 |
Correct |
14 ms |
24168 KB |
Output is correct |
16 |
Correct |
15 ms |
24168 KB |
Output is correct |
17 |
Correct |
714 ms |
71660 KB |
Output is correct |
18 |
Correct |
726 ms |
71060 KB |
Output is correct |
19 |
Correct |
730 ms |
71288 KB |
Output is correct |
20 |
Correct |
684 ms |
71472 KB |
Output is correct |
21 |
Correct |
692 ms |
71784 KB |
Output is correct |
22 |
Correct |
721 ms |
72860 KB |
Output is correct |
23 |
Correct |
739 ms |
72396 KB |
Output is correct |
24 |
Correct |
742 ms |
72988 KB |
Output is correct |
25 |
Correct |
753 ms |
73284 KB |
Output is correct |
26 |
Correct |
749 ms |
72100 KB |
Output is correct |
27 |
Correct |
731 ms |
70444 KB |
Output is correct |
28 |
Correct |
735 ms |
72444 KB |
Output is correct |
29 |
Correct |
714 ms |
72212 KB |
Output is correct |
30 |
Correct |
715 ms |
73200 KB |
Output is correct |
31 |
Correct |
729 ms |
72364 KB |
Output is correct |
32 |
Correct |
694 ms |
72372 KB |
Output is correct |
33 |
Correct |
592 ms |
67096 KB |
Output is correct |
34 |
Correct |
309 ms |
73632 KB |
Output is correct |
35 |
Correct |
274 ms |
65356 KB |
Output is correct |
36 |
Correct |
283 ms |
64284 KB |
Output is correct |
37 |
Correct |
257 ms |
63892 KB |
Output is correct |
38 |
Correct |
287 ms |
65216 KB |
Output is correct |
39 |
Correct |
254 ms |
63548 KB |
Output is correct |
40 |
Correct |
254 ms |
64056 KB |
Output is correct |
41 |
Correct |
241 ms |
63096 KB |
Output is correct |
42 |
Correct |
308 ms |
66304 KB |
Output is correct |
43 |
Correct |
254 ms |
63760 KB |
Output is correct |
44 |
Correct |
625 ms |
70720 KB |
Output is correct |
45 |
Correct |
257 ms |
64092 KB |
Output is correct |
46 |
Correct |
248 ms |
86048 KB |
Output is correct |
47 |
Correct |
184 ms |
76012 KB |
Output is correct |
48 |
Correct |
494 ms |
69788 KB |
Output is correct |
49 |
Correct |
552 ms |
69784 KB |
Output is correct |
50 |
Correct |
453 ms |
68188 KB |
Output is correct |
51 |
Correct |
301 ms |
73832 KB |
Output is correct |
52 |
Correct |
300 ms |
73924 KB |
Output is correct |
53 |
Correct |
300 ms |
73836 KB |
Output is correct |
54 |
Correct |
298 ms |
73720 KB |
Output is correct |
55 |
Correct |
697 ms |
71112 KB |
Output is correct |
56 |
Correct |
359 ms |
73924 KB |
Output is correct |
57 |
Correct |
387 ms |
64528 KB |
Output is correct |
58 |
Correct |
366 ms |
64132 KB |
Output is correct |
59 |
Correct |
347 ms |
63908 KB |
Output is correct |
60 |
Correct |
452 ms |
65640 KB |
Output is correct |
61 |
Correct |
402 ms |
64272 KB |
Output is correct |
62 |
Correct |
355 ms |
64780 KB |
Output is correct |
63 |
Correct |
430 ms |
65436 KB |
Output is correct |
64 |
Correct |
396 ms |
63344 KB |
Output is correct |
65 |
Correct |
430 ms |
65000 KB |
Output is correct |
66 |
Correct |
699 ms |
71068 KB |
Output is correct |
67 |
Correct |
428 ms |
64064 KB |
Output is correct |
68 |
Correct |
278 ms |
88420 KB |
Output is correct |
69 |
Correct |
302 ms |
89264 KB |
Output is correct |
70 |
Correct |
715 ms |
70496 KB |
Output is correct |
71 |
Correct |
725 ms |
70248 KB |
Output is correct |
72 |
Correct |
818 ms |
71312 KB |
Output is correct |
73 |
Correct |
405 ms |
73868 KB |
Output is correct |
74 |
Correct |
369 ms |
73912 KB |
Output is correct |
75 |
Correct |
371 ms |
74012 KB |
Output is correct |
76 |
Correct |
370 ms |
73936 KB |
Output is correct |
77 |
Correct |
897 ms |
74028 KB |
Output is correct |
78 |
Correct |
384 ms |
76224 KB |
Output is correct |
79 |
Correct |
465 ms |
67144 KB |
Output is correct |
80 |
Correct |
485 ms |
65792 KB |
Output is correct |
81 |
Correct |
473 ms |
67076 KB |
Output is correct |
82 |
Correct |
484 ms |
66768 KB |
Output is correct |
83 |
Correct |
453 ms |
66108 KB |
Output is correct |
84 |
Correct |
491 ms |
66408 KB |
Output is correct |
85 |
Correct |
423 ms |
67356 KB |
Output is correct |
86 |
Correct |
470 ms |
67052 KB |
Output is correct |
87 |
Correct |
445 ms |
66324 KB |
Output is correct |
88 |
Correct |
656 ms |
73072 KB |
Output is correct |
89 |
Correct |
438 ms |
66880 KB |
Output is correct |
90 |
Correct |
328 ms |
89140 KB |
Output is correct |
91 |
Correct |
337 ms |
89892 KB |
Output is correct |
92 |
Runtime error |
856 ms |
142596 KB |
Execution killed with signal 6 |
93 |
Halted |
0 ms |
0 KB |
- |