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>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, q;
cin >> n >> q;
vector<pii> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i].first >> v[i].second;
if(n <= 1000 && q <= 100) {
while(q--) {
int s, t;
cin >> s >> t;
vector<int> dist(n+1, -1);
queue<int> q; q.push(s); dist[s] = 0;
while(!q.empty()) {
int u = q.front(); q.pop();
for(int i=1; i<=n; i++) {
if(dist[i] != -1) continue;
if(v[i].first <= v[u].second && v[u].second <= v[i].second) {
dist[i] = dist[u] + 1;
q.push(i);
}
}
}
if(dist[t] == -1) cout << "impossible\n";
else cout << dist[t] << '\n';
}
return 0;
}
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... |