이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int MAXN = 3e4;
const int inf = 1e9;
vector<pii> edges[MAXN];
unordered_set<int> at[MAXN];
int n, m;
int dist[MAXN];
void dijkstra(int s) {
fill(dist, dist+n, inf);
dist[s] = 0;
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.push(pii(0, s));
while (!pq.empty()) {
pii p = pq.top();
pq.pop();
int cur = p.second;
if (dist[cur] < p.first) continue;
for (pii e: edges[cur]) {
if (dist[cur]+e.second < dist[e.first]) {
dist[e.first] = dist[cur]+e.second;
pq.push(pii(dist[e.first], e.first));
}
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m;
int posf;
int poss;
for (int i = 0; i < m; i++) {
int x, y; cin >> x >> y;
if (i == 1) posf = x;
if (i == 0) poss = x;
at[x].insert(y);
}
for (int i = n-1; i >= 0; i--) {
for (int p: at[i]) {
for (int j = i+p; j < n; j += p) {
edges[i].push_back(pii(j, (j-i)/p));
if (at[j].find(p) != at[j].end()) break;
}
}
}
for (int i = 0; i < n; i++) {
for (int p: at[i]) {
for (int j = i-p; j >= 0; j -= p) {
edges[i].push_back(pii(j, (i-j)/p));
if (at[j].find(p) != at[j].end()) break;
}
}
}
dijkstra(poss);
cout << ((dist[posf] == inf) ? (-1) : dist[posf]) << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:60:10: warning: 'poss' may be used uninitialized in this function [-Wmaybe-uninitialized]
60 | dijkstra(poss);
| ~~~~~~~~^~~~~~
skyscraper.cpp:61:21: warning: 'posf' may be used uninitialized in this function [-Wmaybe-uninitialized]
61 | cout << ((dist[posf] == inf) ? (-1) : dist[posf]) << "\n";
| ~~~~~~~~~^
# | 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... |