#include<bits/stdc++.h>
#define debug true
#ifdef DEVAL
#define debug false
#endif
using namespace std;
const int maxn = 1e5 + 10;
struct interval
{
int s, e;
}seg[maxn];
int n, q;
pair < int, int > task[maxn];
void read()
{
cin >> n >> q;
for (int i = 1; i <= n; i ++)
{
cin >> seg[i].s >> seg[i].e;
}
for (int i = 1; i <= q; i ++)
{
cin >> task[i].first >> task[i].second;
}
}
vector < int > adj[maxn];
int used[maxn];
void bfs(int start)
{
for (int i = 1; i <= n; i ++)
used[i] = -1;
used[start] = 0;
queue < int > q;
q.push(start);
while(!q.empty())
{
int v = q.front();
q.pop();
for (int u : adj[v])
{
if (used[u] == - 1)
{
used[u] = used[v] + 1;
q.push(u);
}
}
}
}
void build_graph()
{
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
{
if (seg[j].s <= seg[i].e && seg[i].e <= seg[j].e)
adj[i].push_back(j);
}
}
void answer_queries()
{
for (int i = 1; i <= q; i ++)
{
bfs(task[i].first);
if (used[task[i].second] == -1)
cout << "impossible" << endl;
else
cout << used[task[i].second] << endl;
}
}
void solve()
{
if (debug) exit(0);
read();
build_graph();
answer_queries();
}
int main()
{
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |