#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]==1) S.erase(it);
if(f[y.first] == 0) 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 (){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
21452 KB |
Output is correct |
2 |
Correct |
14 ms |
21472 KB |
Output is correct |
3 |
Correct |
14 ms |
21452 KB |
Output is correct |
4 |
Correct |
12 ms |
21540 KB |
Output is correct |
5 |
Correct |
12 ms |
21520 KB |
Output is correct |
6 |
Correct |
12 ms |
21452 KB |
Output is correct |
7 |
Correct |
12 ms |
21436 KB |
Output is correct |
8 |
Correct |
12 ms |
21452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
21452 KB |
Output is correct |
2 |
Correct |
14 ms |
21472 KB |
Output is correct |
3 |
Correct |
14 ms |
21452 KB |
Output is correct |
4 |
Correct |
12 ms |
21540 KB |
Output is correct |
5 |
Correct |
12 ms |
21520 KB |
Output is correct |
6 |
Correct |
12 ms |
21452 KB |
Output is correct |
7 |
Correct |
12 ms |
21436 KB |
Output is correct |
8 |
Correct |
12 ms |
21452 KB |
Output is correct |
9 |
Correct |
14 ms |
21708 KB |
Output is correct |
10 |
Correct |
14 ms |
21832 KB |
Output is correct |
11 |
Correct |
14 ms |
21820 KB |
Output is correct |
12 |
Correct |
14 ms |
21708 KB |
Output is correct |
13 |
Correct |
13 ms |
21708 KB |
Output is correct |
14 |
Correct |
13 ms |
21724 KB |
Output is correct |
15 |
Correct |
13 ms |
21708 KB |
Output is correct |
16 |
Correct |
13 ms |
21708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
726 ms |
70208 KB |
Output is correct |
2 |
Correct |
727 ms |
69512 KB |
Output is correct |
3 |
Correct |
705 ms |
69640 KB |
Output is correct |
4 |
Correct |
703 ms |
69808 KB |
Output is correct |
5 |
Correct |
690 ms |
70128 KB |
Output is correct |
6 |
Correct |
743 ms |
71424 KB |
Output is correct |
7 |
Correct |
774 ms |
70840 KB |
Output is correct |
8 |
Correct |
758 ms |
71504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
751 ms |
71856 KB |
Output is correct |
2 |
Correct |
711 ms |
70560 KB |
Output is correct |
3 |
Correct |
723 ms |
68876 KB |
Output is correct |
4 |
Correct |
734 ms |
70976 KB |
Output is correct |
5 |
Correct |
715 ms |
70600 KB |
Output is correct |
6 |
Correct |
722 ms |
71460 KB |
Output is correct |
7 |
Correct |
714 ms |
70668 KB |
Output is correct |
8 |
Correct |
717 ms |
70852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
523 ms |
65044 KB |
Output is correct |
2 |
Correct |
311 ms |
68804 KB |
Output is correct |
3 |
Correct |
275 ms |
59896 KB |
Output is correct |
4 |
Correct |
261 ms |
58792 KB |
Output is correct |
5 |
Correct |
266 ms |
58444 KB |
Output is correct |
6 |
Correct |
269 ms |
59704 KB |
Output is correct |
7 |
Correct |
256 ms |
58064 KB |
Output is correct |
8 |
Correct |
284 ms |
58588 KB |
Output is correct |
9 |
Correct |
249 ms |
57556 KB |
Output is correct |
10 |
Correct |
333 ms |
60600 KB |
Output is correct |
11 |
Correct |
257 ms |
58192 KB |
Output is correct |
12 |
Correct |
634 ms |
65572 KB |
Output is correct |
13 |
Correct |
280 ms |
58492 KB |
Output is correct |
14 |
Correct |
248 ms |
80948 KB |
Output is correct |
15 |
Correct |
181 ms |
70724 KB |
Output is correct |
16 |
Correct |
499 ms |
64740 KB |
Output is correct |
17 |
Correct |
566 ms |
64756 KB |
Output is correct |
18 |
Correct |
494 ms |
63044 KB |
Output is correct |
19 |
Correct |
310 ms |
69076 KB |
Output is correct |
20 |
Correct |
302 ms |
69188 KB |
Output is correct |
21 |
Correct |
315 ms |
69232 KB |
Output is correct |
22 |
Correct |
320 ms |
69016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
523 ms |
65044 KB |
Output is correct |
2 |
Correct |
311 ms |
68804 KB |
Output is correct |
3 |
Correct |
275 ms |
59896 KB |
Output is correct |
4 |
Correct |
261 ms |
58792 KB |
Output is correct |
5 |
Correct |
266 ms |
58444 KB |
Output is correct |
6 |
Correct |
269 ms |
59704 KB |
Output is correct |
7 |
Correct |
256 ms |
58064 KB |
Output is correct |
8 |
Correct |
284 ms |
58588 KB |
Output is correct |
9 |
Correct |
249 ms |
57556 KB |
Output is correct |
10 |
Correct |
333 ms |
60600 KB |
Output is correct |
11 |
Correct |
257 ms |
58192 KB |
Output is correct |
12 |
Correct |
634 ms |
65572 KB |
Output is correct |
13 |
Correct |
280 ms |
58492 KB |
Output is correct |
14 |
Correct |
248 ms |
80948 KB |
Output is correct |
15 |
Correct |
181 ms |
70724 KB |
Output is correct |
16 |
Correct |
499 ms |
64740 KB |
Output is correct |
17 |
Correct |
566 ms |
64756 KB |
Output is correct |
18 |
Correct |
494 ms |
63044 KB |
Output is correct |
19 |
Correct |
310 ms |
69076 KB |
Output is correct |
20 |
Correct |
302 ms |
69188 KB |
Output is correct |
21 |
Correct |
315 ms |
69232 KB |
Output is correct |
22 |
Correct |
320 ms |
69016 KB |
Output is correct |
23 |
Correct |
699 ms |
65992 KB |
Output is correct |
24 |
Correct |
358 ms |
69156 KB |
Output is correct |
25 |
Correct |
414 ms |
58936 KB |
Output is correct |
26 |
Correct |
366 ms |
58548 KB |
Output is correct |
27 |
Correct |
341 ms |
58224 KB |
Output is correct |
28 |
Correct |
434 ms |
59972 KB |
Output is correct |
29 |
Correct |
408 ms |
58660 KB |
Output is correct |
30 |
Correct |
368 ms |
59232 KB |
Output is correct |
31 |
Correct |
399 ms |
59844 KB |
Output is correct |
32 |
Correct |
395 ms |
57724 KB |
Output is correct |
33 |
Correct |
472 ms |
59196 KB |
Output is correct |
34 |
Correct |
728 ms |
66176 KB |
Output is correct |
35 |
Correct |
418 ms |
58484 KB |
Output is correct |
36 |
Correct |
282 ms |
83656 KB |
Output is correct |
37 |
Correct |
315 ms |
83684 KB |
Output is correct |
38 |
Correct |
711 ms |
65568 KB |
Output is correct |
39 |
Correct |
691 ms |
65188 KB |
Output is correct |
40 |
Correct |
813 ms |
66264 KB |
Output is correct |
41 |
Correct |
366 ms |
69324 KB |
Output is correct |
42 |
Correct |
363 ms |
69100 KB |
Output is correct |
43 |
Correct |
357 ms |
69060 KB |
Output is correct |
44 |
Correct |
358 ms |
69132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
21452 KB |
Output is correct |
2 |
Correct |
14 ms |
21472 KB |
Output is correct |
3 |
Correct |
14 ms |
21452 KB |
Output is correct |
4 |
Correct |
12 ms |
21540 KB |
Output is correct |
5 |
Correct |
12 ms |
21520 KB |
Output is correct |
6 |
Correct |
12 ms |
21452 KB |
Output is correct |
7 |
Correct |
12 ms |
21436 KB |
Output is correct |
8 |
Correct |
12 ms |
21452 KB |
Output is correct |
9 |
Correct |
14 ms |
21708 KB |
Output is correct |
10 |
Correct |
14 ms |
21832 KB |
Output is correct |
11 |
Correct |
14 ms |
21820 KB |
Output is correct |
12 |
Correct |
14 ms |
21708 KB |
Output is correct |
13 |
Correct |
13 ms |
21708 KB |
Output is correct |
14 |
Correct |
13 ms |
21724 KB |
Output is correct |
15 |
Correct |
13 ms |
21708 KB |
Output is correct |
16 |
Correct |
13 ms |
21708 KB |
Output is correct |
17 |
Correct |
726 ms |
70208 KB |
Output is correct |
18 |
Correct |
727 ms |
69512 KB |
Output is correct |
19 |
Correct |
705 ms |
69640 KB |
Output is correct |
20 |
Correct |
703 ms |
69808 KB |
Output is correct |
21 |
Correct |
690 ms |
70128 KB |
Output is correct |
22 |
Correct |
743 ms |
71424 KB |
Output is correct |
23 |
Correct |
774 ms |
70840 KB |
Output is correct |
24 |
Correct |
758 ms |
71504 KB |
Output is correct |
25 |
Correct |
751 ms |
71856 KB |
Output is correct |
26 |
Correct |
711 ms |
70560 KB |
Output is correct |
27 |
Correct |
723 ms |
68876 KB |
Output is correct |
28 |
Correct |
734 ms |
70976 KB |
Output is correct |
29 |
Correct |
715 ms |
70600 KB |
Output is correct |
30 |
Correct |
722 ms |
71460 KB |
Output is correct |
31 |
Correct |
714 ms |
70668 KB |
Output is correct |
32 |
Correct |
717 ms |
70852 KB |
Output is correct |
33 |
Correct |
523 ms |
65044 KB |
Output is correct |
34 |
Correct |
311 ms |
68804 KB |
Output is correct |
35 |
Correct |
275 ms |
59896 KB |
Output is correct |
36 |
Correct |
261 ms |
58792 KB |
Output is correct |
37 |
Correct |
266 ms |
58444 KB |
Output is correct |
38 |
Correct |
269 ms |
59704 KB |
Output is correct |
39 |
Correct |
256 ms |
58064 KB |
Output is correct |
40 |
Correct |
284 ms |
58588 KB |
Output is correct |
41 |
Correct |
249 ms |
57556 KB |
Output is correct |
42 |
Correct |
333 ms |
60600 KB |
Output is correct |
43 |
Correct |
257 ms |
58192 KB |
Output is correct |
44 |
Correct |
634 ms |
65572 KB |
Output is correct |
45 |
Correct |
280 ms |
58492 KB |
Output is correct |
46 |
Correct |
248 ms |
80948 KB |
Output is correct |
47 |
Correct |
181 ms |
70724 KB |
Output is correct |
48 |
Correct |
499 ms |
64740 KB |
Output is correct |
49 |
Correct |
566 ms |
64756 KB |
Output is correct |
50 |
Correct |
494 ms |
63044 KB |
Output is correct |
51 |
Correct |
310 ms |
69076 KB |
Output is correct |
52 |
Correct |
302 ms |
69188 KB |
Output is correct |
53 |
Correct |
315 ms |
69232 KB |
Output is correct |
54 |
Correct |
320 ms |
69016 KB |
Output is correct |
55 |
Correct |
699 ms |
65992 KB |
Output is correct |
56 |
Correct |
358 ms |
69156 KB |
Output is correct |
57 |
Correct |
414 ms |
58936 KB |
Output is correct |
58 |
Correct |
366 ms |
58548 KB |
Output is correct |
59 |
Correct |
341 ms |
58224 KB |
Output is correct |
60 |
Correct |
434 ms |
59972 KB |
Output is correct |
61 |
Correct |
408 ms |
58660 KB |
Output is correct |
62 |
Correct |
368 ms |
59232 KB |
Output is correct |
63 |
Correct |
399 ms |
59844 KB |
Output is correct |
64 |
Correct |
395 ms |
57724 KB |
Output is correct |
65 |
Correct |
472 ms |
59196 KB |
Output is correct |
66 |
Correct |
728 ms |
66176 KB |
Output is correct |
67 |
Correct |
418 ms |
58484 KB |
Output is correct |
68 |
Correct |
282 ms |
83656 KB |
Output is correct |
69 |
Correct |
315 ms |
83684 KB |
Output is correct |
70 |
Correct |
711 ms |
65568 KB |
Output is correct |
71 |
Correct |
691 ms |
65188 KB |
Output is correct |
72 |
Correct |
813 ms |
66264 KB |
Output is correct |
73 |
Correct |
366 ms |
69324 KB |
Output is correct |
74 |
Correct |
363 ms |
69100 KB |
Output is correct |
75 |
Correct |
357 ms |
69060 KB |
Output is correct |
76 |
Correct |
358 ms |
69132 KB |
Output is correct |
77 |
Correct |
841 ms |
66624 KB |
Output is correct |
78 |
Correct |
366 ms |
69188 KB |
Output is correct |
79 |
Correct |
449 ms |
59132 KB |
Output is correct |
80 |
Correct |
452 ms |
58036 KB |
Output is correct |
81 |
Correct |
428 ms |
59128 KB |
Output is correct |
82 |
Correct |
480 ms |
58924 KB |
Output is correct |
83 |
Correct |
452 ms |
58272 KB |
Output is correct |
84 |
Correct |
469 ms |
58444 KB |
Output is correct |
85 |
Correct |
404 ms |
59432 KB |
Output is correct |
86 |
Correct |
456 ms |
59112 KB |
Output is correct |
87 |
Correct |
427 ms |
58572 KB |
Output is correct |
88 |
Correct |
635 ms |
65636 KB |
Output is correct |
89 |
Correct |
437 ms |
58876 KB |
Output is correct |
90 |
Correct |
324 ms |
83628 KB |
Output is correct |
91 |
Correct |
360 ms |
83768 KB |
Output is correct |
92 |
Runtime error |
786 ms |
134592 KB |
Execution killed with signal 6 |
93 |
Halted |
0 ms |
0 KB |
- |