#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
void solve() {
int n, q;
cin >> n >> q;
vector<pii> v(n);
for (pii &p : v) cin >> p.first >> p.second;
while (q--) {
int a, b;
cin >> a >> b;
--a;--b;
queue<pii> bfs;
bfs.push({a, 0});
int ans = -1;
vector<bool> vis(n, 0);
vis[a] = 1;
while (bfs.size()) {
pii p = bfs.front();
bfs.pop();
if (p.first == b) {
ans = p.second;
break;
}
for (int i = 0; i < n; ++i) if (!vis[i] && v[i].first <= v[p.first].second && v[p.first].second <= v[i].second) {
vis[i] = 1;
bfs.push({i, p.second+1});
}
}
cout << (ans == -1 ? "impossible" : to_string(ans)) << '\n';
}
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1588 ms |
1256 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
131 ms |
348 KB |
Output is correct |
4 |
Correct |
33 ms |
344 KB |
Output is correct |
5 |
Correct |
59 ms |
436 KB |
Output is correct |
6 |
Correct |
55 ms |
348 KB |
Output is correct |
7 |
Correct |
45 ms |
344 KB |
Output is correct |
8 |
Correct |
36 ms |
348 KB |
Output is correct |
9 |
Correct |
36 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
131 ms |
348 KB |
Output is correct |
4 |
Correct |
33 ms |
344 KB |
Output is correct |
5 |
Correct |
59 ms |
436 KB |
Output is correct |
6 |
Correct |
55 ms |
348 KB |
Output is correct |
7 |
Correct |
45 ms |
344 KB |
Output is correct |
8 |
Correct |
36 ms |
348 KB |
Output is correct |
9 |
Correct |
36 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
134 ms |
464 KB |
Output is correct |
13 |
Correct |
34 ms |
348 KB |
Output is correct |
14 |
Correct |
60 ms |
348 KB |
Output is correct |
15 |
Correct |
56 ms |
348 KB |
Output is correct |
16 |
Correct |
45 ms |
344 KB |
Output is correct |
17 |
Correct |
36 ms |
344 KB |
Output is correct |
18 |
Correct |
36 ms |
348 KB |
Output is correct |
19 |
Execution timed out |
1531 ms |
600 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
131 ms |
348 KB |
Output is correct |
4 |
Correct |
33 ms |
344 KB |
Output is correct |
5 |
Correct |
59 ms |
436 KB |
Output is correct |
6 |
Correct |
55 ms |
348 KB |
Output is correct |
7 |
Correct |
45 ms |
344 KB |
Output is correct |
8 |
Correct |
36 ms |
348 KB |
Output is correct |
9 |
Correct |
36 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
135 ms |
484 KB |
Output is correct |
13 |
Correct |
34 ms |
344 KB |
Output is correct |
14 |
Correct |
59 ms |
348 KB |
Output is correct |
15 |
Correct |
56 ms |
348 KB |
Output is correct |
16 |
Correct |
45 ms |
348 KB |
Output is correct |
17 |
Correct |
36 ms |
500 KB |
Output is correct |
18 |
Correct |
36 ms |
348 KB |
Output is correct |
19 |
Execution timed out |
1550 ms |
3156 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1549 ms |
1116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1588 ms |
1256 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |