//Nov21-2020
#define tasknames "aesthetic"
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
const int maxn=3e5+2;
int n, m, x[maxn], y[maxn], c[maxn], maxc[maxn], Time=0, num[maxn], low[maxn];
long long d[2][maxn];
bool ch[2][maxn], kt;
stack<int> st;
struct T
{
int v, w, id;
};
vector<T> a[maxn];
void Dijkstra(int s,int h)
{
priority_queue<pair<long long,int>> pq;
for(int i=1;i<=n;i++)
d[h][i]=1e18;
d[h][s]=0;
pq.push({0,s});
while(!pq.empty())
{
auto u=pq.top();
pq.pop();
u.first=-u.first;
if(u.first!=d[h][u.second])
continue;
for(T v:a[u.second])
if(d[h][v.v]>u.first+v.w)
{
d[h][v.v]=u.first+v.w;
pq.push({-d[h][v.v],v.v});
}
}
}
void Enter()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int u, v, w;
cin>>u>>v>>w;
a[u].push_back({v,w,i});
a[v].push_back({u,w,i});
x[i]=u;y[i]=v;c[i]=w;
}
for(int i=m;i>0;i--)
maxc[i]=max(maxc[i+1],c[i+1]);
Dijkstra(1,0);
Dijkstra(n,1);
}
void Tarjan(int u,int par)
{
num[u]=low[u]=++Time;
for(T v:a[u])
{
if(!ch[0][v.id])continue;
if(num[v.v])
{
if(v.v!=par)
low[u]=min(low[u],num[v.v]);
}
else
{
Tarjan(v.v,u);
if(low[v.v]>num[u]&&num[n]>=num[v.v]&&ch[1][v.id])
kt=true;
else low[u]=min(low[u],low[v.v]);
}
}
}
bool Check(long long mid)
{
for(int i=1;i<=m;i++)
{
long long dist=min(d[0][x[i]]+d[1][y[i]],d[1][x[i]]+d[0][y[i]])+c[i];
ch[0][i]=(dist<=mid);
ch[1][i]=((dist+maxc[i])>mid);
}
fill_n(num,n+1,0);
fill_n(low,n+1,1e9);
Time=0;kt=false;
Tarjan(1,0);
if(kt||num[n]==0)return true;
return false;
}
void Solve()
{
long long l=d[0][n], r=d[0][n]+maxc[1], mid;
while(l<=r)
{
mid=(l+r)/2;
if(Check(mid))
l=mid+1;
else r=mid-1;
}
cout<<l;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
Enter();
Solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
6 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
6 ms |
7404 KB |
Output is correct |
5 |
Correct |
6 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
6 ms |
7404 KB |
Output is correct |
8 |
Correct |
6 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
6 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
6 ms |
7404 KB |
Output is correct |
5 |
Correct |
6 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
6 ms |
7404 KB |
Output is correct |
8 |
Correct |
6 ms |
7404 KB |
Output is correct |
9 |
Correct |
7 ms |
7660 KB |
Output is correct |
10 |
Correct |
7 ms |
7660 KB |
Output is correct |
11 |
Correct |
8 ms |
7660 KB |
Output is correct |
12 |
Correct |
7 ms |
7660 KB |
Output is correct |
13 |
Correct |
7 ms |
7660 KB |
Output is correct |
14 |
Correct |
7 ms |
7660 KB |
Output is correct |
15 |
Correct |
7 ms |
7660 KB |
Output is correct |
16 |
Correct |
7 ms |
7660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
655 ms |
38596 KB |
Output is correct |
2 |
Correct |
653 ms |
38764 KB |
Output is correct |
3 |
Correct |
651 ms |
38508 KB |
Output is correct |
4 |
Correct |
667 ms |
38508 KB |
Output is correct |
5 |
Correct |
723 ms |
38508 KB |
Output is correct |
6 |
Correct |
689 ms |
39184 KB |
Output is correct |
7 |
Correct |
697 ms |
39020 KB |
Output is correct |
8 |
Correct |
685 ms |
39424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
714 ms |
39404 KB |
Output is correct |
2 |
Correct |
686 ms |
38860 KB |
Output is correct |
3 |
Correct |
692 ms |
38636 KB |
Output is correct |
4 |
Correct |
669 ms |
39268 KB |
Output is correct |
5 |
Correct |
677 ms |
38776 KB |
Output is correct |
6 |
Correct |
674 ms |
38896 KB |
Output is correct |
7 |
Correct |
662 ms |
38764 KB |
Output is correct |
8 |
Correct |
667 ms |
39020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
413 ms |
34020 KB |
Output is correct |
2 |
Correct |
195 ms |
32748 KB |
Output is correct |
3 |
Correct |
278 ms |
37532 KB |
Output is correct |
4 |
Correct |
270 ms |
37740 KB |
Output is correct |
5 |
Correct |
278 ms |
37484 KB |
Output is correct |
6 |
Correct |
277 ms |
37612 KB |
Output is correct |
7 |
Correct |
269 ms |
37740 KB |
Output is correct |
8 |
Correct |
274 ms |
37740 KB |
Output is correct |
9 |
Correct |
274 ms |
37740 KB |
Output is correct |
10 |
Correct |
274 ms |
38024 KB |
Output is correct |
11 |
Correct |
282 ms |
37868 KB |
Output is correct |
12 |
Correct |
419 ms |
34168 KB |
Output is correct |
13 |
Correct |
271 ms |
37740 KB |
Output is correct |
14 |
Correct |
150 ms |
49900 KB |
Output is correct |
15 |
Correct |
157 ms |
49900 KB |
Output is correct |
16 |
Correct |
405 ms |
34312 KB |
Output is correct |
17 |
Correct |
422 ms |
33520 KB |
Output is correct |
18 |
Correct |
411 ms |
34020 KB |
Output is correct |
19 |
Correct |
191 ms |
32748 KB |
Output is correct |
20 |
Correct |
191 ms |
32748 KB |
Output is correct |
21 |
Correct |
189 ms |
32748 KB |
Output is correct |
22 |
Correct |
192 ms |
33096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
413 ms |
34020 KB |
Output is correct |
2 |
Correct |
195 ms |
32748 KB |
Output is correct |
3 |
Correct |
278 ms |
37532 KB |
Output is correct |
4 |
Correct |
270 ms |
37740 KB |
Output is correct |
5 |
Correct |
278 ms |
37484 KB |
Output is correct |
6 |
Correct |
277 ms |
37612 KB |
Output is correct |
7 |
Correct |
269 ms |
37740 KB |
Output is correct |
8 |
Correct |
274 ms |
37740 KB |
Output is correct |
9 |
Correct |
274 ms |
37740 KB |
Output is correct |
10 |
Correct |
274 ms |
38024 KB |
Output is correct |
11 |
Correct |
282 ms |
37868 KB |
Output is correct |
12 |
Correct |
419 ms |
34168 KB |
Output is correct |
13 |
Correct |
271 ms |
37740 KB |
Output is correct |
14 |
Correct |
150 ms |
49900 KB |
Output is correct |
15 |
Correct |
157 ms |
49900 KB |
Output is correct |
16 |
Correct |
405 ms |
34312 KB |
Output is correct |
17 |
Correct |
422 ms |
33520 KB |
Output is correct |
18 |
Correct |
411 ms |
34020 KB |
Output is correct |
19 |
Correct |
191 ms |
32748 KB |
Output is correct |
20 |
Correct |
191 ms |
32748 KB |
Output is correct |
21 |
Correct |
189 ms |
32748 KB |
Output is correct |
22 |
Correct |
192 ms |
33096 KB |
Output is correct |
23 |
Correct |
462 ms |
35144 KB |
Output is correct |
24 |
Correct |
243 ms |
32876 KB |
Output is correct |
25 |
Correct |
273 ms |
33772 KB |
Output is correct |
26 |
Correct |
280 ms |
32944 KB |
Output is correct |
27 |
Correct |
283 ms |
33004 KB |
Output is correct |
28 |
Correct |
286 ms |
34156 KB |
Output is correct |
29 |
Correct |
280 ms |
33004 KB |
Output is correct |
30 |
Correct |
285 ms |
33516 KB |
Output is correct |
31 |
Correct |
286 ms |
33644 KB |
Output is correct |
32 |
Correct |
283 ms |
33132 KB |
Output is correct |
33 |
Correct |
285 ms |
33772 KB |
Output is correct |
34 |
Correct |
460 ms |
35120 KB |
Output is correct |
35 |
Correct |
282 ms |
33516 KB |
Output is correct |
36 |
Correct |
173 ms |
44912 KB |
Output is correct |
37 |
Correct |
174 ms |
45552 KB |
Output is correct |
38 |
Correct |
458 ms |
34240 KB |
Output is correct |
39 |
Correct |
446 ms |
34644 KB |
Output is correct |
40 |
Correct |
470 ms |
35400 KB |
Output is correct |
41 |
Correct |
240 ms |
32876 KB |
Output is correct |
42 |
Correct |
247 ms |
33004 KB |
Output is correct |
43 |
Correct |
246 ms |
32748 KB |
Output is correct |
44 |
Correct |
243 ms |
32876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
6 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
6 ms |
7404 KB |
Output is correct |
5 |
Correct |
6 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
6 ms |
7404 KB |
Output is correct |
8 |
Correct |
6 ms |
7404 KB |
Output is correct |
9 |
Correct |
7 ms |
7660 KB |
Output is correct |
10 |
Correct |
7 ms |
7660 KB |
Output is correct |
11 |
Correct |
8 ms |
7660 KB |
Output is correct |
12 |
Correct |
7 ms |
7660 KB |
Output is correct |
13 |
Correct |
7 ms |
7660 KB |
Output is correct |
14 |
Correct |
7 ms |
7660 KB |
Output is correct |
15 |
Correct |
7 ms |
7660 KB |
Output is correct |
16 |
Correct |
7 ms |
7660 KB |
Output is correct |
17 |
Correct |
655 ms |
38596 KB |
Output is correct |
18 |
Correct |
653 ms |
38764 KB |
Output is correct |
19 |
Correct |
651 ms |
38508 KB |
Output is correct |
20 |
Correct |
667 ms |
38508 KB |
Output is correct |
21 |
Correct |
723 ms |
38508 KB |
Output is correct |
22 |
Correct |
689 ms |
39184 KB |
Output is correct |
23 |
Correct |
697 ms |
39020 KB |
Output is correct |
24 |
Correct |
685 ms |
39424 KB |
Output is correct |
25 |
Correct |
714 ms |
39404 KB |
Output is correct |
26 |
Correct |
686 ms |
38860 KB |
Output is correct |
27 |
Correct |
692 ms |
38636 KB |
Output is correct |
28 |
Correct |
669 ms |
39268 KB |
Output is correct |
29 |
Correct |
677 ms |
38776 KB |
Output is correct |
30 |
Correct |
674 ms |
38896 KB |
Output is correct |
31 |
Correct |
662 ms |
38764 KB |
Output is correct |
32 |
Correct |
667 ms |
39020 KB |
Output is correct |
33 |
Correct |
413 ms |
34020 KB |
Output is correct |
34 |
Correct |
195 ms |
32748 KB |
Output is correct |
35 |
Correct |
278 ms |
37532 KB |
Output is correct |
36 |
Correct |
270 ms |
37740 KB |
Output is correct |
37 |
Correct |
278 ms |
37484 KB |
Output is correct |
38 |
Correct |
277 ms |
37612 KB |
Output is correct |
39 |
Correct |
269 ms |
37740 KB |
Output is correct |
40 |
Correct |
274 ms |
37740 KB |
Output is correct |
41 |
Correct |
274 ms |
37740 KB |
Output is correct |
42 |
Correct |
274 ms |
38024 KB |
Output is correct |
43 |
Correct |
282 ms |
37868 KB |
Output is correct |
44 |
Correct |
419 ms |
34168 KB |
Output is correct |
45 |
Correct |
271 ms |
37740 KB |
Output is correct |
46 |
Correct |
150 ms |
49900 KB |
Output is correct |
47 |
Correct |
157 ms |
49900 KB |
Output is correct |
48 |
Correct |
405 ms |
34312 KB |
Output is correct |
49 |
Correct |
422 ms |
33520 KB |
Output is correct |
50 |
Correct |
411 ms |
34020 KB |
Output is correct |
51 |
Correct |
191 ms |
32748 KB |
Output is correct |
52 |
Correct |
191 ms |
32748 KB |
Output is correct |
53 |
Correct |
189 ms |
32748 KB |
Output is correct |
54 |
Correct |
192 ms |
33096 KB |
Output is correct |
55 |
Correct |
462 ms |
35144 KB |
Output is correct |
56 |
Correct |
243 ms |
32876 KB |
Output is correct |
57 |
Correct |
273 ms |
33772 KB |
Output is correct |
58 |
Correct |
280 ms |
32944 KB |
Output is correct |
59 |
Correct |
283 ms |
33004 KB |
Output is correct |
60 |
Correct |
286 ms |
34156 KB |
Output is correct |
61 |
Correct |
280 ms |
33004 KB |
Output is correct |
62 |
Correct |
285 ms |
33516 KB |
Output is correct |
63 |
Correct |
286 ms |
33644 KB |
Output is correct |
64 |
Correct |
283 ms |
33132 KB |
Output is correct |
65 |
Correct |
285 ms |
33772 KB |
Output is correct |
66 |
Correct |
460 ms |
35120 KB |
Output is correct |
67 |
Correct |
282 ms |
33516 KB |
Output is correct |
68 |
Correct |
173 ms |
44912 KB |
Output is correct |
69 |
Correct |
174 ms |
45552 KB |
Output is correct |
70 |
Correct |
458 ms |
34240 KB |
Output is correct |
71 |
Correct |
446 ms |
34644 KB |
Output is correct |
72 |
Correct |
470 ms |
35400 KB |
Output is correct |
73 |
Correct |
240 ms |
32876 KB |
Output is correct |
74 |
Correct |
247 ms |
33004 KB |
Output is correct |
75 |
Correct |
246 ms |
32748 KB |
Output is correct |
76 |
Correct |
243 ms |
32876 KB |
Output is correct |
77 |
Correct |
601 ms |
37584 KB |
Output is correct |
78 |
Correct |
456 ms |
35160 KB |
Output is correct |
79 |
Correct |
421 ms |
40044 KB |
Output is correct |
80 |
Correct |
438 ms |
39916 KB |
Output is correct |
81 |
Correct |
429 ms |
39916 KB |
Output is correct |
82 |
Correct |
415 ms |
39788 KB |
Output is correct |
83 |
Correct |
417 ms |
40300 KB |
Output is correct |
84 |
Correct |
427 ms |
40428 KB |
Output is correct |
85 |
Correct |
415 ms |
39916 KB |
Output is correct |
86 |
Correct |
426 ms |
40044 KB |
Output is correct |
87 |
Correct |
437 ms |
40172 KB |
Output is correct |
88 |
Correct |
587 ms |
36696 KB |
Output is correct |
89 |
Correct |
426 ms |
40172 KB |
Output is correct |
90 |
Correct |
290 ms |
45552 KB |
Output is correct |
91 |
Correct |
303 ms |
46320 KB |
Output is correct |
92 |
Correct |
570 ms |
37572 KB |
Output is correct |
93 |
Correct |
566 ms |
37204 KB |
Output is correct |
94 |
Correct |
547 ms |
36808 KB |
Output is correct |
95 |
Correct |
443 ms |
35052 KB |
Output is correct |
96 |
Correct |
460 ms |
35180 KB |
Output is correct |
97 |
Correct |
452 ms |
35052 KB |
Output is correct |
98 |
Correct |
457 ms |
35052 KB |
Output is correct |