#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
int n,qu;
cin>>n>>qu;
vector<array<int,3>> events(n);
for(int i=0;i<n;i++)
{
int e,s;
cin>>s>>e;
events[i]={s,e,i};
}
while(qu--)
{
int a,b;
cin>>a>>b;
a--;
b--;
vector<int> dis(n+1,-1);
queue<int> q;
q.push(a);
while(!q.empty())
{
int x=q.front();
q.pop();
for(int i=0;i<n;i++)
{
if(dis[i]!=-1)
continue;
if(events[i][0] <= events[x][1] && events[x][0] <= events[i][0]) {
dis[i] = dis[x] + 1;
q.push(i);
}
}
}
if(dis[b] == -1)
cout<<"impossible"<<endl;
else
cout<<dis[b]<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |