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>
#define forin(i, a, b) for(int i = a; i <= b; ++i)
#define ii pair<int, int>
using namespace std;
const int N = 3e4 + 10;
int n, m;
int b[N], p[N], d[N];
vector<ii> adj[N];
void dijkstra(int s) {
priority_queue<ii, vector<ii>, greater<ii> > pq;
fill(d + 1, d + m + 1, 1e18);
pq.push({0, s});
d[s] = 0;
while(!pq.empty()) {
int kc, u; tie(kc, u) = pq.top();
pq.pop();
if(kc != d[u]) continue;
for(auto e : adj[u]) {
int w, v; tie(w, v) = e;
if(d[v] <= d[u] + w) continue;
d[v] = d[u] + w;
pq.push({d[v], v});
}
}
}
int main () {
cin.tie(0)->sync_with_stdio(0);
if(fopen("Task.inp","r")) {
freopen("Task.inp","r",stdin);
freopen("WA.out","w",stdout);
}
cin>>n>>m;
forin(i, 1, m) cin>>b[i]>>p[i];
forin(i, 1, m) forin(j, 1, m) if(i != j) {
bool ok = ((b[j] - b[i]) % p[i] == 0);
if(ok) {
int w = abs(b[j] - b[i]) / p[i];
adj[i].push_back({w, j});
}
}
dijkstra(1);
cout<<d[2];
}
Compilation message (stderr)
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | freopen("Task.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("WA.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | 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... |