/*
+----------------------------------------------------------------+
| In the name of Allah, the most Gracious and the most Merciful. |
+----------------------------------------------------------------+
+------------------------------------------------------+
| Ба номи Худованди беандоза Mеҳрабон ва ниҳоят Бораҳм |
+------------------------------------------------------+
+-----------------------------------------+
| Во имя Аллаха Милостивого, Милосердного |
+-----------------------------------------+
This world is a trial for us
And we know well that we must
Obey the orders from my lord
To avoid all sins and seek reward
*/
# include <bits/stdc++.h>
# define FILE
using namespace std;
const int N = 3e5 + 100;
const long long inf = 1e15;
int n, m, timm, curr, bridge, U[N], V[N], W[N], maxW[N], tin[N], low[N];
long long dist[2][N], within[N], without[N];
vector < int > graph[N];
void bfs( int v, long long *dist ){
for( int i = 1; i <= n; i ++ ) dist[i] = inf;
dist[v] = 0;
priority_queue < pair <long long, int>, vector<pair<long long, int>>, greater<pair<long long, int> > > pq;
pq.push({0,v});
while( !pq.empty() ){
long long dst; int v; tie(dst, v) = pq.top(); pq.pop();
if( dst > dist[v] )continue;
for( auto i: graph[v] ){
int to = (v == V[i]?U[i]:V[i]);
if( dist[to] > dist[v] + W[i] ){
dist[to] = dist[v] + W[i];
pq.push({dist[to], to});
}
}
}
}
void dfs( int v, int f, int ras ){
tin[v] = low[v] = ++timm;
for( auto i: graph[v] ){
if( without[i] > ras )continue;
int to = (v==V[i]?U[i]:V[i]);
if( tin[to] <= curr ){
dfs(to, v, ras);
if( low[to] > tin[v] && tin[n] >= tin[to] && within[i] > ras )
bridge = 1;
low[v] = min( low[v], low[to]);
}else if( to != f ){
low[v] = min( low[v], tin[to]);
}
}
}
bool check( long long ras){
curr = timm;
bridge = 0;
dfs(1, 0, ras);
//cout << "check " << curr << ' ' << tin[n] << ' ' <<bridge << endl;
if( tin[n] <= curr) return 0;
if( bridge )return 0;
return true;
}
int main(){
# ifdef FILEs
freopen( "input.txt", "r", stdin );
freopen( "output.txt", "w", stdout );
# endif
ios_base::sync_with_stdio(false);
cin >> n >> m;
for( int i = 1; i <= m; i ++ ){
cin >> V[i] >> U[i] >> W[i];
graph[V[i]].push_back( i );
graph[U[i]].push_back( i );
}
for( int i = m-1; i >= 1; i -- ){
maxW[i] = max( W[i+1], maxW[i+1]);
}
bfs( 1, dist[0]);
bfs( n, dist[1]);
for( int i = 1; i <= m; i ++ ){
without[i] = min( dist[0][V[i]] + dist[1][U[i]], dist[0][U[i]] + dist[1][V[i]]) + W[i];
within[i] = without[i] + maxW[i];
}
/*
for( int i = 1; i <= m; i ++ ){
cout << i << ' ' << V[i] <<' ' << U[i] << ' ' << without[i] << ' ' << within[i] <<' ' <<maxW[i]<< endl;
}cout << endl;
*/
long long l = dist[0][n]-1, r = dist[0][n] + maxW[1]+1;
while( r - l > 1 ){
long long mid = ( l + r ) >> 1;
//cout << l << ' '<< mid << ' ' << r << endl;
if( check(mid) )
r = mid;
else
l = mid;
}
cout << r;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Incorrect |
5 ms |
7424 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Incorrect |
5 ms |
7424 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
553 ms |
30456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
561 ms |
30840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
466 ms |
28120 KB |
Output is correct |
2 |
Correct |
205 ms |
31652 KB |
Output is correct |
3 |
Correct |
264 ms |
30968 KB |
Output is correct |
4 |
Correct |
263 ms |
30968 KB |
Output is correct |
5 |
Correct |
266 ms |
30968 KB |
Output is correct |
6 |
Correct |
266 ms |
31352 KB |
Output is correct |
7 |
Correct |
272 ms |
31096 KB |
Output is correct |
8 |
Correct |
266 ms |
31224 KB |
Output is correct |
9 |
Correct |
263 ms |
31096 KB |
Output is correct |
10 |
Correct |
272 ms |
31304 KB |
Output is correct |
11 |
Correct |
266 ms |
31228 KB |
Output is correct |
12 |
Correct |
459 ms |
27520 KB |
Output is correct |
13 |
Correct |
266 ms |
31096 KB |
Output is correct |
14 |
Correct |
155 ms |
43512 KB |
Output is correct |
15 |
Correct |
158 ms |
43512 KB |
Output is correct |
16 |
Correct |
464 ms |
27712 KB |
Output is correct |
17 |
Correct |
452 ms |
27552 KB |
Output is correct |
18 |
Correct |
462 ms |
27400 KB |
Output is correct |
19 |
Correct |
200 ms |
31608 KB |
Output is correct |
20 |
Correct |
203 ms |
31636 KB |
Output is correct |
21 |
Correct |
200 ms |
31608 KB |
Output is correct |
22 |
Correct |
211 ms |
31764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
466 ms |
28120 KB |
Output is correct |
2 |
Correct |
205 ms |
31652 KB |
Output is correct |
3 |
Correct |
264 ms |
30968 KB |
Output is correct |
4 |
Correct |
263 ms |
30968 KB |
Output is correct |
5 |
Correct |
266 ms |
30968 KB |
Output is correct |
6 |
Correct |
266 ms |
31352 KB |
Output is correct |
7 |
Correct |
272 ms |
31096 KB |
Output is correct |
8 |
Correct |
266 ms |
31224 KB |
Output is correct |
9 |
Correct |
263 ms |
31096 KB |
Output is correct |
10 |
Correct |
272 ms |
31304 KB |
Output is correct |
11 |
Correct |
266 ms |
31228 KB |
Output is correct |
12 |
Correct |
459 ms |
27520 KB |
Output is correct |
13 |
Correct |
266 ms |
31096 KB |
Output is correct |
14 |
Correct |
155 ms |
43512 KB |
Output is correct |
15 |
Correct |
158 ms |
43512 KB |
Output is correct |
16 |
Correct |
464 ms |
27712 KB |
Output is correct |
17 |
Correct |
452 ms |
27552 KB |
Output is correct |
18 |
Correct |
462 ms |
27400 KB |
Output is correct |
19 |
Correct |
200 ms |
31608 KB |
Output is correct |
20 |
Correct |
203 ms |
31636 KB |
Output is correct |
21 |
Correct |
200 ms |
31608 KB |
Output is correct |
22 |
Correct |
211 ms |
31764 KB |
Output is correct |
23 |
Correct |
535 ms |
28576 KB |
Output is correct |
24 |
Correct |
257 ms |
31608 KB |
Output is correct |
25 |
Correct |
271 ms |
27256 KB |
Output is correct |
26 |
Correct |
270 ms |
26464 KB |
Output is correct |
27 |
Correct |
266 ms |
26360 KB |
Output is correct |
28 |
Correct |
276 ms |
27384 KB |
Output is correct |
29 |
Correct |
268 ms |
26540 KB |
Output is correct |
30 |
Correct |
269 ms |
26908 KB |
Output is correct |
31 |
Correct |
271 ms |
27000 KB |
Output is correct |
32 |
Correct |
268 ms |
26488 KB |
Output is correct |
33 |
Correct |
268 ms |
27132 KB |
Output is correct |
34 |
Correct |
519 ms |
27644 KB |
Output is correct |
35 |
Correct |
285 ms |
26872 KB |
Output is correct |
36 |
Correct |
176 ms |
37432 KB |
Output is correct |
37 |
Correct |
178 ms |
37564 KB |
Output is correct |
38 |
Correct |
521 ms |
28224 KB |
Output is correct |
39 |
Correct |
514 ms |
27744 KB |
Output is correct |
40 |
Correct |
540 ms |
28880 KB |
Output is correct |
41 |
Correct |
260 ms |
31736 KB |
Output is correct |
42 |
Correct |
268 ms |
31736 KB |
Output is correct |
43 |
Correct |
265 ms |
31608 KB |
Output is correct |
44 |
Correct |
258 ms |
31712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Incorrect |
5 ms |
7424 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |