#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int MAX = 3e5 + 5;
vector<int> adj[1001];
int color[1001], dis[1001];
void bfs(int s){
queue<int> q;
q.push(s);
dis[s] = 0;
color[s] = 1;
while(!q.empty()){
int u = q.front();
q.pop();
for(auto v : adj[u]){
if(color[v]) continue;
color[v] = 1;
dis[v] = dis[u] + 1;
q.push(v);
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, q;
cin>>n>>q;
vector<int> S(n + 1), E(n + 1);
for (int i = 1; i <= n; i++)
{
cin>>S[i]>>E[i];
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if(S[j] <= E[i] && E[i] <= E[j]) adj[i].push_back(j);
}
}
while(q--){
memset(color, 0, sizeof(color));
memset(dis, -1, sizeof(dis));
int s, e;
cin>>s>>e;
bfs(s);
if(dis[e] != -1) cout<<dis[e]<<endl;
else cout<<"impossible\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
495 ms |
2124 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
352 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 |
368 KB |
Output is correct |
6 |
Correct |
12 ms |
1236 KB |
Output is correct |
7 |
Correct |
28 ms |
1992 KB |
Output is correct |
8 |
Correct |
28 ms |
3032 KB |
Output is correct |
9 |
Correct |
140 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
352 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 |
368 KB |
Output is correct |
6 |
Correct |
12 ms |
1236 KB |
Output is correct |
7 |
Correct |
28 ms |
1992 KB |
Output is correct |
8 |
Correct |
28 ms |
3032 KB |
Output is correct |
9 |
Correct |
140 ms |
4436 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
408 KB |
Output is correct |
13 |
Correct |
5 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
352 KB |
Output is correct |
15 |
Correct |
12 ms |
1108 KB |
Output is correct |
16 |
Correct |
26 ms |
1876 KB |
Output is correct |
17 |
Correct |
30 ms |
3028 KB |
Output is correct |
18 |
Correct |
157 ms |
4380 KB |
Output is correct |
19 |
Runtime error |
33 ms |
12260 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
352 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 |
368 KB |
Output is correct |
6 |
Correct |
12 ms |
1236 KB |
Output is correct |
7 |
Correct |
28 ms |
1992 KB |
Output is correct |
8 |
Correct |
28 ms |
3032 KB |
Output is correct |
9 |
Correct |
140 ms |
4436 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
356 KB |
Output is correct |
13 |
Correct |
6 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
388 KB |
Output is correct |
15 |
Correct |
11 ms |
1124 KB |
Output is correct |
16 |
Correct |
26 ms |
1996 KB |
Output is correct |
17 |
Correct |
41 ms |
3028 KB |
Output is correct |
18 |
Correct |
146 ms |
4384 KB |
Output is correct |
19 |
Runtime error |
498 ms |
2264 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
523 ms |
2156 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
495 ms |
2124 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |