Submission #896564

#TimeUsernameProblemLanguageResultExecution timeMemory
896564AiperiiiRailway Trip (JOI17_railway_trip)C++14
5 / 100
2066 ms12156 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,q; cin>>n>>k>>q; 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(q--){ int a,b; cin>>a>>b; a--; b--; set <pair <int,int> > st; vector <int> d(n,1e18); st.insert({0,a}); d[a]=0; while(!st.empty()){ int v=st.begin()->second; st.erase(st.begin()); for(auto to : g[v]){ if(d[to]>d[v]+1){ st.erase({d[to],to}); d[to]=d[v]+1; st.insert({d[to],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...