#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
const int N = 30005;
vector<pair<ll,ll>>G[N];
vector<ll>dist(N,1e18),par(N,-1);
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<pair<int,int>> a(m);
for(int i = 0; i < m; i++) {
cin >> a[i].first >> a[i].second;
}
for(int i = 0; i < m; i++) {
for(int j = 0; j < m; j++) {
if(i == j) {
continue;
}
for(int k = 0; k < 100; k++) {
if(a[i].first + k * a[i].second == a[j].first) {
G[i].push_back({j, k});
}
if(a[i].first - k * a[i].second == a[j].first) {
G[i].push_back({j, k});
}
}
}
}
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>pq;
pq.push({0,0});
dist[0] = 0;
vector<bool>vis(n+1,false);
while(pq.size()) {
ll d,u;
tie(d,u) = pq.top();
pq.pop();
if(vis[u]) continue;
vis[u] = true;
for(auto X:G[u]) {
if(dist[X.first] > dist[u] + X.second) {
dist[X.first] = dist[u] + X.second;
pq.push({dist[X.first],X.first});
par[X.first] = u;
}
}
}
cout << dist[1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1624 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1652 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1628 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1648 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1644 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1628 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1628 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |