#include <bits/stdc++.h>
//#define int long long
using namespace std;
int N,Q,S[5001],E[5001],X,Y;
bool ADJ[5001][5001],VIS[5001];
int DIST[5001][5001];
void BFS(int x,int DIS = 0){
for(int i = 0;i <= 5000; i += 1)VIS[i] = 0;
queue<pair<int,int>>Q;
Q.push({x,0});
while(Q.size()){
int V = Q.front().first, S = Q.front().second;
Q.pop();
if(VIS[V])continue;
VIS[V] = 1;
DIST[x][V] = S;
for(int i = 0; i <= 5000; i += 1)if(ADJ[V][i])Q.push({i, S + 1});
}
}
int32_t main()
{
cin.tie(0),iostream::sync_with_stdio(0);
cin>>N>>Q;
for(int i = 0; i <= 5000; i += 1)for(int l = 0; l <= 5000; l += 1)DIST[i][l] = -1;
for(int i = 0; i < N; i += 1){
cin>>S[i]>>E[i];
}
for(int i = 0; i < N; i += 1){
for(int l = 0; l < N; l += 1){
ADJ[i][l] = ((S[l] <= E[i]&&E[i]<=E[l])?1:0);
}
}
for(int i = 0; i < N; i += 1)BFS(i);
while(Q--){
cin>>X>>Y;
(DIST[X - 1][Y - 1] == -1?cout<<"impossible\n":cout<<DIST[X - 1][Y - 1]<<'\n');
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
98168 KB |
Output is correct |
2 |
Runtime error |
157 ms |
198992 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
98216 KB |
Output is correct |
2 |
Correct |
43 ms |
98244 KB |
Output is correct |
3 |
Correct |
1380 ms |
103124 KB |
Output is correct |
4 |
Correct |
732 ms |
103120 KB |
Output is correct |
5 |
Correct |
1322 ms |
103108 KB |
Output is correct |
6 |
Correct |
1403 ms |
103512 KB |
Output is correct |
7 |
Execution timed out |
1567 ms |
105740 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
98216 KB |
Output is correct |
2 |
Correct |
43 ms |
98244 KB |
Output is correct |
3 |
Correct |
1380 ms |
103124 KB |
Output is correct |
4 |
Correct |
732 ms |
103120 KB |
Output is correct |
5 |
Correct |
1322 ms |
103108 KB |
Output is correct |
6 |
Correct |
1403 ms |
103512 KB |
Output is correct |
7 |
Execution timed out |
1567 ms |
105740 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
98216 KB |
Output is correct |
2 |
Correct |
43 ms |
98244 KB |
Output is correct |
3 |
Correct |
1380 ms |
103124 KB |
Output is correct |
4 |
Correct |
732 ms |
103120 KB |
Output is correct |
5 |
Correct |
1322 ms |
103108 KB |
Output is correct |
6 |
Correct |
1403 ms |
103512 KB |
Output is correct |
7 |
Execution timed out |
1567 ms |
105740 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
198924 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
98168 KB |
Output is correct |
2 |
Runtime error |
157 ms |
198992 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |