#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5;
ll n , m , au[N] , av[N] , aw[N];
ll u , v , w , A;
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);
scanf("%lld%lld" , &n , &m);
for(int i =0; i <m; ++i) scanf("%lld%lld%lld" , &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(!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;
u = n;
ll ans = d1[n];
//cout << "ka";
ll k;
while(1){
//cout << "ha";
if(u == 1)break;
for(ll v : T[u]) q(v);
u = par[u];
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;
printf("%lld" ,ans);
}
Compilation message
Aesthetic.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main (){
| ^~~~
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%lld%lld" , &n , &m);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Aesthetic.cpp:30:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | for(int i =0; i <m; ++i) scanf("%lld%lld%lld" , &au[i] , &av[i], &aw[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
21452 KB |
Output is correct |
2 |
Correct |
12 ms |
21444 KB |
Output is correct |
3 |
Correct |
12 ms |
21536 KB |
Output is correct |
4 |
Correct |
12 ms |
21548 KB |
Output is correct |
5 |
Correct |
12 ms |
21452 KB |
Output is correct |
6 |
Correct |
12 ms |
21452 KB |
Output is correct |
7 |
Correct |
13 ms |
21452 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 |
12 ms |
21444 KB |
Output is correct |
3 |
Correct |
12 ms |
21536 KB |
Output is correct |
4 |
Correct |
12 ms |
21548 KB |
Output is correct |
5 |
Correct |
12 ms |
21452 KB |
Output is correct |
6 |
Correct |
12 ms |
21452 KB |
Output is correct |
7 |
Correct |
13 ms |
21452 KB |
Output is correct |
8 |
Correct |
12 ms |
21452 KB |
Output is correct |
9 |
Correct |
13 ms |
21844 KB |
Output is correct |
10 |
Correct |
13 ms |
21836 KB |
Output is correct |
11 |
Correct |
13 ms |
21708 KB |
Output is correct |
12 |
Correct |
13 ms |
21708 KB |
Output is correct |
13 |
Correct |
15 ms |
21708 KB |
Output is correct |
14 |
Correct |
15 ms |
21708 KB |
Output is correct |
15 |
Correct |
13 ms |
21708 KB |
Output is correct |
16 |
Correct |
14 ms |
21780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
699 ms |
70068 KB |
Output is correct |
2 |
Correct |
709 ms |
69512 KB |
Output is correct |
3 |
Correct |
686 ms |
69712 KB |
Output is correct |
4 |
Correct |
714 ms |
69972 KB |
Output is correct |
5 |
Correct |
692 ms |
70196 KB |
Output is correct |
6 |
Correct |
703 ms |
71316 KB |
Output is correct |
7 |
Correct |
753 ms |
70772 KB |
Output is correct |
8 |
Correct |
713 ms |
71416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
709 ms |
71716 KB |
Output is correct |
2 |
Correct |
695 ms |
70532 KB |
Output is correct |
3 |
Correct |
709 ms |
68872 KB |
Output is correct |
4 |
Correct |
761 ms |
71072 KB |
Output is correct |
5 |
Correct |
720 ms |
70664 KB |
Output is correct |
6 |
Correct |
723 ms |
71412 KB |
Output is correct |
7 |
Correct |
696 ms |
70628 KB |
Output is correct |
8 |
Correct |
719 ms |
70900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
543 ms |
64888 KB |
Output is correct |
2 |
Correct |
294 ms |
68764 KB |
Output is correct |
3 |
Correct |
267 ms |
59848 KB |
Output is correct |
4 |
Correct |
256 ms |
58752 KB |
Output is correct |
5 |
Correct |
249 ms |
58340 KB |
Output is correct |
6 |
Correct |
289 ms |
59724 KB |
Output is correct |
7 |
Correct |
245 ms |
57988 KB |
Output is correct |
8 |
Correct |
249 ms |
58556 KB |
Output is correct |
9 |
Correct |
260 ms |
57500 KB |
Output is correct |
10 |
Correct |
268 ms |
60592 KB |
Output is correct |
11 |
Correct |
254 ms |
58172 KB |
Output is correct |
12 |
Correct |
599 ms |
65600 KB |
Output is correct |
13 |
Correct |
254 ms |
58532 KB |
Output is correct |
14 |
Correct |
249 ms |
80900 KB |
Output is correct |
15 |
Correct |
184 ms |
70728 KB |
Output is correct |
16 |
Correct |
479 ms |
64852 KB |
Output is correct |
17 |
Correct |
578 ms |
64756 KB |
Output is correct |
18 |
Correct |
444 ms |
63152 KB |
Output is correct |
19 |
Correct |
294 ms |
69060 KB |
Output is correct |
20 |
Correct |
312 ms |
69180 KB |
Output is correct |
21 |
Correct |
291 ms |
69060 KB |
Output is correct |
22 |
Correct |
289 ms |
69004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
543 ms |
64888 KB |
Output is correct |
2 |
Correct |
294 ms |
68764 KB |
Output is correct |
3 |
Correct |
267 ms |
59848 KB |
Output is correct |
4 |
Correct |
256 ms |
58752 KB |
Output is correct |
5 |
Correct |
249 ms |
58340 KB |
Output is correct |
6 |
Correct |
289 ms |
59724 KB |
Output is correct |
7 |
Correct |
245 ms |
57988 KB |
Output is correct |
8 |
Correct |
249 ms |
58556 KB |
Output is correct |
9 |
Correct |
260 ms |
57500 KB |
Output is correct |
10 |
Correct |
268 ms |
60592 KB |
Output is correct |
11 |
Correct |
254 ms |
58172 KB |
Output is correct |
12 |
Correct |
599 ms |
65600 KB |
Output is correct |
13 |
Correct |
254 ms |
58532 KB |
Output is correct |
14 |
Correct |
249 ms |
80900 KB |
Output is correct |
15 |
Correct |
184 ms |
70728 KB |
Output is correct |
16 |
Correct |
479 ms |
64852 KB |
Output is correct |
17 |
Correct |
578 ms |
64756 KB |
Output is correct |
18 |
Correct |
444 ms |
63152 KB |
Output is correct |
19 |
Correct |
294 ms |
69060 KB |
Output is correct |
20 |
Correct |
312 ms |
69180 KB |
Output is correct |
21 |
Correct |
291 ms |
69060 KB |
Output is correct |
22 |
Correct |
289 ms |
69004 KB |
Output is correct |
23 |
Correct |
709 ms |
66112 KB |
Output is correct |
24 |
Correct |
352 ms |
69188 KB |
Output is correct |
25 |
Correct |
387 ms |
58976 KB |
Output is correct |
26 |
Correct |
358 ms |
58472 KB |
Output is correct |
27 |
Correct |
344 ms |
58252 KB |
Output is correct |
28 |
Correct |
430 ms |
59964 KB |
Output is correct |
29 |
Correct |
422 ms |
58632 KB |
Output is correct |
30 |
Correct |
379 ms |
59332 KB |
Output is correct |
31 |
Correct |
404 ms |
59820 KB |
Output is correct |
32 |
Correct |
379 ms |
57980 KB |
Output is correct |
33 |
Correct |
408 ms |
59336 KB |
Output is correct |
34 |
Correct |
677 ms |
65876 KB |
Output is correct |
35 |
Correct |
395 ms |
58500 KB |
Output is correct |
36 |
Correct |
279 ms |
83744 KB |
Output is correct |
37 |
Correct |
295 ms |
83668 KB |
Output is correct |
38 |
Correct |
662 ms |
65576 KB |
Output is correct |
39 |
Correct |
710 ms |
65456 KB |
Output is correct |
40 |
Correct |
799 ms |
66384 KB |
Output is correct |
41 |
Correct |
385 ms |
69080 KB |
Output is correct |
42 |
Correct |
360 ms |
69132 KB |
Output is correct |
43 |
Correct |
365 ms |
69060 KB |
Output is correct |
44 |
Correct |
362 ms |
69492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
21452 KB |
Output is correct |
2 |
Correct |
12 ms |
21444 KB |
Output is correct |
3 |
Correct |
12 ms |
21536 KB |
Output is correct |
4 |
Correct |
12 ms |
21548 KB |
Output is correct |
5 |
Correct |
12 ms |
21452 KB |
Output is correct |
6 |
Correct |
12 ms |
21452 KB |
Output is correct |
7 |
Correct |
13 ms |
21452 KB |
Output is correct |
8 |
Correct |
12 ms |
21452 KB |
Output is correct |
9 |
Correct |
13 ms |
21844 KB |
Output is correct |
10 |
Correct |
13 ms |
21836 KB |
Output is correct |
11 |
Correct |
13 ms |
21708 KB |
Output is correct |
12 |
Correct |
13 ms |
21708 KB |
Output is correct |
13 |
Correct |
15 ms |
21708 KB |
Output is correct |
14 |
Correct |
15 ms |
21708 KB |
Output is correct |
15 |
Correct |
13 ms |
21708 KB |
Output is correct |
16 |
Correct |
14 ms |
21780 KB |
Output is correct |
17 |
Correct |
699 ms |
70068 KB |
Output is correct |
18 |
Correct |
709 ms |
69512 KB |
Output is correct |
19 |
Correct |
686 ms |
69712 KB |
Output is correct |
20 |
Correct |
714 ms |
69972 KB |
Output is correct |
21 |
Correct |
692 ms |
70196 KB |
Output is correct |
22 |
Correct |
703 ms |
71316 KB |
Output is correct |
23 |
Correct |
753 ms |
70772 KB |
Output is correct |
24 |
Correct |
713 ms |
71416 KB |
Output is correct |
25 |
Correct |
709 ms |
71716 KB |
Output is correct |
26 |
Correct |
695 ms |
70532 KB |
Output is correct |
27 |
Correct |
709 ms |
68872 KB |
Output is correct |
28 |
Correct |
761 ms |
71072 KB |
Output is correct |
29 |
Correct |
720 ms |
70664 KB |
Output is correct |
30 |
Correct |
723 ms |
71412 KB |
Output is correct |
31 |
Correct |
696 ms |
70628 KB |
Output is correct |
32 |
Correct |
719 ms |
70900 KB |
Output is correct |
33 |
Correct |
543 ms |
64888 KB |
Output is correct |
34 |
Correct |
294 ms |
68764 KB |
Output is correct |
35 |
Correct |
267 ms |
59848 KB |
Output is correct |
36 |
Correct |
256 ms |
58752 KB |
Output is correct |
37 |
Correct |
249 ms |
58340 KB |
Output is correct |
38 |
Correct |
289 ms |
59724 KB |
Output is correct |
39 |
Correct |
245 ms |
57988 KB |
Output is correct |
40 |
Correct |
249 ms |
58556 KB |
Output is correct |
41 |
Correct |
260 ms |
57500 KB |
Output is correct |
42 |
Correct |
268 ms |
60592 KB |
Output is correct |
43 |
Correct |
254 ms |
58172 KB |
Output is correct |
44 |
Correct |
599 ms |
65600 KB |
Output is correct |
45 |
Correct |
254 ms |
58532 KB |
Output is correct |
46 |
Correct |
249 ms |
80900 KB |
Output is correct |
47 |
Correct |
184 ms |
70728 KB |
Output is correct |
48 |
Correct |
479 ms |
64852 KB |
Output is correct |
49 |
Correct |
578 ms |
64756 KB |
Output is correct |
50 |
Correct |
444 ms |
63152 KB |
Output is correct |
51 |
Correct |
294 ms |
69060 KB |
Output is correct |
52 |
Correct |
312 ms |
69180 KB |
Output is correct |
53 |
Correct |
291 ms |
69060 KB |
Output is correct |
54 |
Correct |
289 ms |
69004 KB |
Output is correct |
55 |
Correct |
709 ms |
66112 KB |
Output is correct |
56 |
Correct |
352 ms |
69188 KB |
Output is correct |
57 |
Correct |
387 ms |
58976 KB |
Output is correct |
58 |
Correct |
358 ms |
58472 KB |
Output is correct |
59 |
Correct |
344 ms |
58252 KB |
Output is correct |
60 |
Correct |
430 ms |
59964 KB |
Output is correct |
61 |
Correct |
422 ms |
58632 KB |
Output is correct |
62 |
Correct |
379 ms |
59332 KB |
Output is correct |
63 |
Correct |
404 ms |
59820 KB |
Output is correct |
64 |
Correct |
379 ms |
57980 KB |
Output is correct |
65 |
Correct |
408 ms |
59336 KB |
Output is correct |
66 |
Correct |
677 ms |
65876 KB |
Output is correct |
67 |
Correct |
395 ms |
58500 KB |
Output is correct |
68 |
Correct |
279 ms |
83744 KB |
Output is correct |
69 |
Correct |
295 ms |
83668 KB |
Output is correct |
70 |
Correct |
662 ms |
65576 KB |
Output is correct |
71 |
Correct |
710 ms |
65456 KB |
Output is correct |
72 |
Correct |
799 ms |
66384 KB |
Output is correct |
73 |
Correct |
385 ms |
69080 KB |
Output is correct |
74 |
Correct |
360 ms |
69132 KB |
Output is correct |
75 |
Correct |
365 ms |
69060 KB |
Output is correct |
76 |
Correct |
362 ms |
69492 KB |
Output is correct |
77 |
Correct |
815 ms |
66792 KB |
Output is correct |
78 |
Correct |
357 ms |
69312 KB |
Output is correct |
79 |
Correct |
463 ms |
59232 KB |
Output is correct |
80 |
Correct |
448 ms |
57832 KB |
Output is correct |
81 |
Correct |
457 ms |
59244 KB |
Output is correct |
82 |
Correct |
466 ms |
58928 KB |
Output is correct |
83 |
Correct |
436 ms |
58304 KB |
Output is correct |
84 |
Correct |
459 ms |
58444 KB |
Output is correct |
85 |
Correct |
413 ms |
59452 KB |
Output is correct |
86 |
Correct |
491 ms |
59088 KB |
Output is correct |
87 |
Correct |
440 ms |
58356 KB |
Output is correct |
88 |
Correct |
610 ms |
65680 KB |
Output is correct |
89 |
Correct |
438 ms |
58856 KB |
Output is correct |
90 |
Correct |
298 ms |
83712 KB |
Output is correct |
91 |
Correct |
352 ms |
83708 KB |
Output is correct |
92 |
Runtime error |
799 ms |
134588 KB |
Execution killed with signal 6 |
93 |
Halted |
0 ms |
0 KB |
- |