# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1120216 | vjudge1 | Event Hopping (BOI22_events) | C++14 | 1559 ms | 306528 KiB |
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 f first
#define s second
typedef long long ll;
vector<ll> g[200100];
ll d[200100];
bool ok(pair<ll, pair<ll, ll>> a, pair<ll, pair<ll, ll>> b) {
return (b.s.f <= a.f);
}
void solve() {
ll n; cin>>n;
ll Q; cin>>Q;
vector<pair<ll, pair<ll, ll>>> v;
for(ll i=1; i<=n; i++) {
ll l,r; cin>>l>>r;
v.push_back({r, {l, i}});
}
sort(v.begin(), v.end());
for(ll i=0; i<v.size(); i++) {
for(ll j=0; j<v.size(); j++) {
if(ok(v[i], v[j])) {
g[v[i].s.s].push_back(v[j].s.s);
}
}
}
while(Q--) {
ll x,y; cin>>x>>y;
queue<ll> q;
for(ll i=1; i<=n; i++) d[i]=1e18;
d[x]=0;
q.push(x);
while(!q.empty()) {
ll v=q.front();
q.pop();
for(auto to: g[v]) {
if(d[to] > d[v]+1) {
d[to]=d[v]+1;
q.push(to);
}
}
}
if(d[y] == 1e18) cout<<"impossible\n";
else cout<<d[y]<<'\n';
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
cout<<'\n';
}
}
Compilation message (stderr)
# | 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... |