#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
vector<int> g[N];
int n, q;
int l[N], r[N];
int dist[N];
bool mark[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
for(int i = 0; i < n; i++) cin >> l[i] >> r[i];
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(l[j] <= r[i] && r[i] <= r[j]) g[i].push_back(j);
while(q--) {
int x, y;
cin >> x >> y;
x--;
y--;
for(int i = 0; i < n; i++) {
dist[i] = 1e9;
mark[i] = false;
}
dist[x] = 0;
queue<int> q;
q.push(x);
while(!q.empty()) {
int u = q.front();
q.pop();
mark[u] = true;
for(int v : g[u]) {
if(mark[v]) continue;
q.push(v);
dist[v] = min(dist[v], dist[u] + 1);
}
}
if(dist[y] == 1e9) cout << "impossible\n";
else cout << dist[y] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Runtime error |
3 ms |
872 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
7 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
404 KB |
Output is correct |
5 |
Correct |
6 ms |
356 KB |
Output is correct |
6 |
Correct |
274 ms |
1284 KB |
Output is correct |
7 |
Execution timed out |
1574 ms |
3392 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
7 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
404 KB |
Output is correct |
5 |
Correct |
6 ms |
356 KB |
Output is correct |
6 |
Correct |
274 ms |
1284 KB |
Output is correct |
7 |
Execution timed out |
1574 ms |
3392 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
7 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
404 KB |
Output is correct |
5 |
Correct |
6 ms |
356 KB |
Output is correct |
6 |
Correct |
274 ms |
1284 KB |
Output is correct |
7 |
Execution timed out |
1574 ms |
3392 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
852 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Runtime error |
3 ms |
872 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |