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>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef home
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
int n, m, k, a, b;
cin >> n >> m >> k >> a >> b, --k;
vector<vector<int>> adj(n);
for (int u, v; m--;) {
cin >> u >> v, --u, --v;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
for (auto& vt : adj)
sort(vt.begin(), vt.end());
queue<int> q;
vector<int> step(n, -1);
step[k] = 0;
q.emplace(k);
while (!q.empty()) {
const auto u = q.front();
q.pop();
for (const auto& v : adj[u])
if (step[v] == -1) {
step[v] = step[u] + 1;
q.emplace(v);
}
}
vector<int> jump(n, -1);
jump[k] = 0;
q.emplace(k);
while (!q.empty()) {
const auto u = q.front();
q.pop();
for (const auto& via : adj[u])
adj[via].erase(remove_if(adj[via].begin(), adj[via].end(), [&](auto& v) {
if (~jump[v] || binary_search(adj[u].begin(), adj[u].end(), v)) return false;
jump[v] = jump[u] + 1;
q.emplace(v);
return true;
}),
adj[via].end());
}
for (int i = 0; i < n; ++i)
cout << min({step[i] * a,
(step[i] & 1) * a + (step[i] >> 1) * b,
~jump[i] ? jump[i] * b : INT_MAX})
<< '\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... |
# | 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... |