Submission #896566

#TimeUsernameProblemLanguageResultExecution timeMemory
896566AiperiiiRailway Trip (JOI17_railway_trip)C++14
20 / 100
2062 ms10876 KiB
#include <bits/stdc++.h> #define int long long #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back using namespace std; signed main(){ ios_base::sync_with_stdio(); cin.tie(0); int n,k,qu; cin>>n>>k>>qu; vector <int> l(n); for(int i=0;i<n;i++)cin>>l[i]; vector <int> g[n]; for(int i=0;i<n;i++){ int mx=0; for(int j=i+1;j<n;j++){ if(l[j]>mx){ mx=l[j]; g[i].pb(j); g[j].pb(i); } if(mx>=l[i])break; } } while(qu--){ int a,b; cin>>a>>b; a--; b--; queue <int> q; vector <int> d(n,1e18); q.push(a); d[a]=0; while(!q.empty()){ int v=q.front(); q.pop(); for(auto to : g[v]){ if(d[to]>d[v]+1){ d[to]=d[v]+1; q.push(to); } } } int x=d[b]-1; cout<<x<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...