#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n,m; cin>>n>>m;
vector<pair<int,int>> doges;
for (int i=0; i<n; i++) {
int b,p; cin>>b>>p;
doges.push_back({b,p});
}
vector<vector<pair<int,int>>> al(n,vector<pair<int,int>>());
vector<int> done(n,0);
queue<int> q;
q.push(0);
done[0]=1;
done[1]=1;
while (!q.empty()) {
int t=q.front(); q.pop();
for (int i=0; i<n; i++) {
if (i==t) continue;
int d=abs(doges[i].first-doges[t].first);
if (d%doges[t].second==0) {
al[t].push_back({i,d/doges[t].second});
if (!done[i]) {
q.push(i);
done[i]=1;
}
}
}
}
vector<int> dist(n,1e9);
dist[0]=0;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> p;
p.push({0,0});
while (!p.empty()) {
int t=p.top().second; p.pop();
for (auto v: al[t]) {
if (dist[t]+v.second<dist[v.first]) {
dist[v.first]=dist[t]+v.second;
p.push({dist[v.first],v.first});
}
}
}
cout<<dist[1];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |