#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, q;
cin >> n >> q;
vector<pii> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i].first >> v[i].second;
if(n <= 1000 && q <= 100) {
while(q--) {
int s, t;
cin >> s >> t;
vector<int> dist(n+1, -1);
queue<int> q; q.push(s); dist[s] = 0;
while(!q.empty()) {
int u = q.front(); q.pop();
for(int i=1; i<=n; i++) {
if(dist[i] != -1) continue;
if(v[i].first <= v[u].second && v[u].second <= v[i].second) {
dist[i] = dist[u] + 1;
q.push(i);
}
}
}
if(dist[t] == -1) cout << "impossible\n";
else cout << dist[t] << '\n';
}
return 0;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
11 ms |
3288 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
106 ms |
348 KB |
Output is correct |
4 |
Correct |
30 ms |
344 KB |
Output is correct |
5 |
Correct |
59 ms |
344 KB |
Output is correct |
6 |
Correct |
42 ms |
348 KB |
Output is correct |
7 |
Correct |
48 ms |
348 KB |
Output is correct |
8 |
Correct |
39 ms |
348 KB |
Output is correct |
9 |
Correct |
66 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
106 ms |
348 KB |
Output is correct |
4 |
Correct |
30 ms |
344 KB |
Output is correct |
5 |
Correct |
59 ms |
344 KB |
Output is correct |
6 |
Correct |
42 ms |
348 KB |
Output is correct |
7 |
Correct |
48 ms |
348 KB |
Output is correct |
8 |
Correct |
39 ms |
348 KB |
Output is correct |
9 |
Correct |
66 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
121 ms |
348 KB |
Output is correct |
13 |
Correct |
28 ms |
348 KB |
Output is correct |
14 |
Correct |
60 ms |
348 KB |
Output is correct |
15 |
Correct |
42 ms |
348 KB |
Output is correct |
16 |
Correct |
50 ms |
468 KB |
Output is correct |
17 |
Correct |
38 ms |
348 KB |
Output is correct |
18 |
Correct |
61 ms |
464 KB |
Output is correct |
19 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
106 ms |
348 KB |
Output is correct |
4 |
Correct |
30 ms |
344 KB |
Output is correct |
5 |
Correct |
59 ms |
344 KB |
Output is correct |
6 |
Correct |
42 ms |
348 KB |
Output is correct |
7 |
Correct |
48 ms |
348 KB |
Output is correct |
8 |
Correct |
39 ms |
348 KB |
Output is correct |
9 |
Correct |
66 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
109 ms |
348 KB |
Output is correct |
13 |
Correct |
28 ms |
348 KB |
Output is correct |
14 |
Correct |
61 ms |
456 KB |
Output is correct |
15 |
Correct |
42 ms |
344 KB |
Output is correct |
16 |
Correct |
48 ms |
348 KB |
Output is correct |
17 |
Correct |
38 ms |
348 KB |
Output is correct |
18 |
Correct |
56 ms |
344 KB |
Output is correct |
19 |
Incorrect |
11 ms |
3164 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
11 ms |
3288 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |