이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
using ll = long long;
const int mod = 1e9+7;
void solve(int tc) {
int n, m, s, t;
cin >> n >> m;
vector<set<int>> ju(n);
set<int> p;
vector<vector<pair<int, int>>> adj(n);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
ju[a].insert(b);
p.insert(b);
if (i==0) s = a;
if (i==1) t = a;
}
for (int i = 0; i < n; ++i) {
for (int x : ju[i]) {
int cur = i;
while (cur+x < n) {
cur += x;
adj[i].push_back({cur, (cur-i)/x});
if (ju[cur].count(x))
break;
}
cur = i;
while (cur-x >= 0) {
cur -= x;
adj[i].push_back({cur, (i-cur)/x});
if (ju[cur].count(x))
break;
}
}
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
pq.push({0, s});
vector<int> dist(n, (1<<30));
dist[s] = 0;
while (!pq.empty()) {
auto [d, u] = pq.top();
pq.pop();
if (dist[u] < d)
continue;
for (auto [v, dd] : adj[u]) {
if (dist[v] <= dist[u]+dd)
continue;
dist[v] = dist[u] + dd;
pq.push({dist[v], v});
}
}
cout << (dist[t]==(1<<30)?-1:dist[t]) << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'void solve(int)':
skyscraper.cpp:51:11: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | dist[s] = 0;
| ^
skyscraper.cpp:64:20: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | cout << (dist[t]==(1<<30)?-1:dist[t]) << '\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... |