#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define sqrt sqrtl
using namespace std;
const long long oo = 1e9;
int sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
freopen ( "sum.in", "r", stdin )
*/
int n, m, x, y, a[ 100001 ], b[ 100001 ], d[ 100001 ], d1[ 5001 ][ 5001 ];
vector <int> v[ 100001 ];
set <pair<int, int> > st;
void bfs( int u ) {
for ( int i = 1; i <= n; i ++ )
d[ i ] = oo;
d[ u ] = 0;
st.insert( { d[ u ], u } );
while ( st.size() ) {
u = st.begin()->second;
st.erase( st.begin() );
for ( auto to : v[ u ] ) {
if ( d[ to ] > d[ u ] + 1 ) {
st.erase( { d[ to ], to } );
d[ to ] = d[ u ] + 1;
st.insert( { d[ to ], to } );
}
}
}
}
main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ] >> b[ i ];
}
if ( n <= 5000 ) {
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= n; j ++ ) {
if ( a[ j ] <= b[ i ] && b[ i ] <= b[ j ] && i != j ) {
v[ i ].push_back( j );
}
}
}
for ( int i = 1; i <= n; i ++ ) {
bfs( i );
for ( int j = 1; j <= n; j ++ ) {
d1[ i ][ j ] = d[ j ];
}
}
while ( m -- ) {
cin >> x >> y;
if ( d1[ x ][ y ] == oo )
cout << "impossible\n";
else
cout << d1[ x ][ y ] << "\n";
}
return 0;
}
else if ( m <= 100 ) {
for ( int i = 1; i <= n; i ++ ) {
}
while ( m -- ) {
cin >> x >> y;
}
}
}
Compilation message
events.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
66 | main () {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
19 ms |
3444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
28 ms |
10552 KB |
Output is correct |
4 |
Correct |
19 ms |
10624 KB |
Output is correct |
5 |
Correct |
34 ms |
10600 KB |
Output is correct |
6 |
Correct |
97 ms |
11336 KB |
Output is correct |
7 |
Correct |
219 ms |
12244 KB |
Output is correct |
8 |
Correct |
242 ms |
13256 KB |
Output is correct |
9 |
Correct |
1144 ms |
14784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
28 ms |
10552 KB |
Output is correct |
4 |
Correct |
19 ms |
10624 KB |
Output is correct |
5 |
Correct |
34 ms |
10600 KB |
Output is correct |
6 |
Correct |
97 ms |
11336 KB |
Output is correct |
7 |
Correct |
219 ms |
12244 KB |
Output is correct |
8 |
Correct |
242 ms |
13256 KB |
Output is correct |
9 |
Correct |
1144 ms |
14784 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
28 ms |
10620 KB |
Output is correct |
13 |
Correct |
19 ms |
10620 KB |
Output is correct |
14 |
Correct |
33 ms |
10576 KB |
Output is correct |
15 |
Correct |
101 ms |
11332 KB |
Output is correct |
16 |
Correct |
223 ms |
12236 KB |
Output is correct |
17 |
Correct |
242 ms |
13248 KB |
Output is correct |
18 |
Correct |
1149 ms |
14692 KB |
Output is correct |
19 |
Execution timed out |
1578 ms |
40508 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
28 ms |
10552 KB |
Output is correct |
4 |
Correct |
19 ms |
10624 KB |
Output is correct |
5 |
Correct |
34 ms |
10600 KB |
Output is correct |
6 |
Correct |
97 ms |
11336 KB |
Output is correct |
7 |
Correct |
219 ms |
12244 KB |
Output is correct |
8 |
Correct |
242 ms |
13256 KB |
Output is correct |
9 |
Correct |
1144 ms |
14784 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
30 ms |
10852 KB |
Output is correct |
13 |
Correct |
19 ms |
10612 KB |
Output is correct |
14 |
Correct |
33 ms |
10648 KB |
Output is correct |
15 |
Correct |
98 ms |
11364 KB |
Output is correct |
16 |
Correct |
227 ms |
12216 KB |
Output is correct |
17 |
Correct |
244 ms |
13284 KB |
Output is correct |
18 |
Correct |
1159 ms |
14672 KB |
Output is correct |
19 |
Incorrect |
19 ms |
3436 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
19 ms |
3444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |