This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define S first
#define E second
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, q; cin >> n >> q;
pair<int, int> ev[n];
for(int i = 0; i < n; i++) cin >> ev[i].S >> ev[i].E;
vector<int> adj[n];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(i != j && ev[j].S <= ev[i].E && ev[i].E <= ev[j].E) adj[i].push_back(j);
while(q--){
int s, e; cin >> s >> e; s--; e--;
vector<int> d(n, -1); queue<int> q;
d[s] = 0;
q.push(s);
while(!q.empty()){
int u = q.front(); q.pop();
if(u == e) break;
for(int v : adj[u]){
if(d[v] != -1) continue;
d[v] = d[u] + 1;
q.push(v);
}
}
if(d[e] == -1) cout << "impossible\n";
else cout << d[e] << '\n';
}
}
# | 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... |