#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 5e3 + 2;
struct nd {
int x;
int y;
int idx;
bool operator < (const nd& oth) const {
return make_pair(x, y) < make_pair(oth.x, oth.y);
}
} a [maxn];
int dist [maxn][maxn];
vector <int> ad [maxn];
void prec (int u, int x) {
queue <int> q;
q.push(u);
dist[u][x] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v: ad[u]){
if (dist[u][x] + 1 < dist[v][x]) {
dist[v][x] = dist[u][x] + 1;
q.push(v);
}
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n,q;
cin >> n >> q;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++) dist[i][j] = 1e9;
cin >> a[i].x >> a[i].y;
a[i].idx = i;
}
cout << "\n";
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (i != j && a[j].x <= a[i].y && a[i].y <= a[j].y) {
cout << i << " " << j << "\n";
ad[i].push_back(j);
}
}
}
// sort(a, a + n);
for (int i = 0; i < n; i++){
prec(i, i);
}
// for (int i = 0; i < n; i++){
// for (int j = 0; j < n; j++){
// cout << i << " " << j << " " << dist[j][i] << "\n";
// }
// }
while (q--){
int x,y;
cin >> x >> y;
x--, y--;
cout << (dist[y][x] == 1e9 ? "impossible": to_string(dist[y][x])) << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
329 ms |
199460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |