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;
int main(void){
int n,m;
int arr[30001][2];
cin >> n >> m;
for(int i=0;i<m;i++)
cin >> arr[i][0] >> arr[i][1];
long long dist[30001];
dist[0]=0;
for(int i=1;i<m;i++)
dist[i]=10e15;
priority_queue<pair<long long,int> >q;
q.push({0,0});
while(!q.empty()){
int cur=q.top().second;
long long curdist=-q.top().first;
q.pop();
for(int i=0;i<m;i++){
if(abs(arr[cur][0]-arr[i][0])%arr[cur][1]!=0){
continue;
}
int nxtdist=abs(arr[cur][0]-arr[i][0])/arr[cur][1];
if(curdist+nxtdist<dist[i]){
dist[i]=curdist+nxtdist;
q.push({-dist[i],i});
cout << i << endl;
}
}
}
if(dist[1]>10e12)cout << -1;
else
cout << dist[1];
}
# | 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... |