이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
int n, m, s, t, cs, ct, x, y, z;
int main() {
scanf("%d %d %d %d %d %d", &n, &m, &s, &t, &cs, &ct);
vector<vector<pii>> v(n + 5, vector<pii>());
while (m--) scanf("%d %d %d", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z);
vector<ll> d(n + 5, 1e18);
vector<vector<int>> par(n + 5, vector<int>());
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.emplace(d[s] = 0, s);
while (!pq.empty()) {
auto [nd, nn] = pq.top(); pq.pop();
for (auto &[tn, td]: v[nn]) {
if (d[tn] > d[nn] + td) par[tn].clear(), par[tn].emplace_back(nn), pq.emplace(d[tn] = d[nn] + td, tn);
else if (d[tn] == d[nn] + td) par[tn].emplace_back(nn);
}
}
vector<int> u{t};
for (int i = 0; i < u.size(); i++) {
for (auto &e: par[u.back()]) u.emplace_back(e);
}
for (auto &e: u) v[n + 1].emplace_back(e, 0), v[e].emplace_back(n + 1, 0);
vector<ll> d2(n + 5, 1e18);
pq.emplace(d2[cs] = 0, cs);
while (!pq.empty()) {
auto [nd, nn] = pq.top(); pq.pop();
for (auto &[tn, td]: v[nn]) if (d2[tn] > d2[nn] + td) pq.emplace(d2[tn] = d2[nn] + td, tn);
}
printf("%lld", d2[ct]);
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < u.size(); i++) {
| ~~^~~~~~~~~~
commuter_pass.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d %d %d %d %d %d", &n, &m, &s, &t, &cs, &ct);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:12:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | while (m--) scanf("%d %d %d", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |