# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040082 | Marco_Escandon | Event Hopping (BOI22_events) | C++11 | 1593 ms | 524288 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;
typedef long long ll;
const ll MOD = 1000000007;
const string ny[2] = {"No", "Yes"};
#define x first
#define y second
vector<vector<ll>> G(200000);
ll cmc(ll n,ll a,ll b)
{
vector<ll> v(n+2, 1e9);
priority_queue<pair<ll,ll>>q;
q.push({0,a});
while(!q.empty())
{
pair<ll,ll> a=q.top();q.pop();
if(v[a.y]==1e9)
{
v[a.y]=-a.x;
if(a.y==b) return -a.x;
for(auto i:G[a.y])
if(v[i]==1e9)
q.push({a.x-1,i});
}
}
return 1e9;
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll n,q;
cin>>n>>q;
vector<pair<ll,ll>> cad;
vector<pair<ll,ll>> input;input.push_back({0,0});
for(int i=1; i<=n; i++)
{
ll a,b;
cin>>a>>b;
input.push_back({a,b});
cad.push_back({a,i});
cad.push_back({b,i});
}
sort(cad.begin(),cad.end());
set<ll> s;
for(int i=0; i<cad.size(); i++)
{
vector<ll> temp,temp2;
ll a=i;
while(i<cad.size()&&cad[a].x==cad[i].x){
temp.push_back(cad[i].y);
i++;
}
i--;
for(auto j:temp)
{
if(s.find(j)!=s.end())
temp2.push_back(j);
else s.insert(j);
}
for(auto j:temp2) for(auto k:s) G[j].push_back(k);
for(auto j:temp2) if(s.find(j)!=s.end()) s.erase(j);
}
for(int i=0; i<q; i++)
{
ll a,b;
cin>>a>>b;
if(input[a].y>input[b].y){ cout<<"impossible"<<"\n"; continue;}
a=cmc(n,a,b);
if(a==1e9) cout<<"impossible"<<"\n";
else cout<<a<<"\n";
}
return 0;
}
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... |