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 LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=2505;
const int INF=1e9;
inline int id(int a,int b){
return a*N+b;
}
int32_t main() {
LCBorz;
int n;cin>>n;
vector<int> adj[N*N],dis(N*N,INF);
vector<int> b(N),c(N);
for(int i=1;i<=n;i++){
cin>>b[i]>>c[i];
for(int j=1;j<=i;j++){
for(int k=i;k<=n;k++){
adj[id(j,k)].push_back(id(min(b[i],j),max(c[i],k)));
//cout<<id(j,k)<<' '<<id(min(b[i],j),max(c[i],k))<<endl;
}
}
}
int q1;cin>>q1;
int p;cin>>p;
queue<int> q;
q.push(id(b[p],c[p]));
dis[id(b[p],c[p])]=1;
while(q.size()){
int p=q.front();
q.pop();
for(int j:adj[p]){
if(dis[j]==INF){
dis[j]=dis[p]+1;
q.push(j);
}
}
}
int ans=dis[id(1,n)];
cout<<(ans==INF?-1:ans)<<endl;
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... |