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 FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
set<int> graph[100001], second_visit[100001];
int visited[100001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k, a, b;
cin >> n >> m >> k >> a >> b;
FOR(i, 0, m) {
int u, v;
cin >> u >> v;
graph[u].insert(v);
graph[v].insert(u);
second_visit[u].insert(v);
second_visit[v].insert(u);
}
priority_queue<pair<int, int>> pq;
pq.push({-1, k});
while (pq.size()) {
pair<int, int> curr = pq.top();
pq.pop();
if (!visited[curr.second]) {
visited[curr.second] = -curr.first;
for (int i : graph[curr.second]) {
pq.push({curr.first - a, i});
vector<int> to_remove;
for (int j : second_visit[i]) {
if (graph[curr.second].find(j) == graph[curr.second].end()) {
to_remove.push_back(j);
pq.push({curr.first - b, j});
}
}
for (int j : to_remove) second_visit[i].erase(j);
}
}
}
FOR(i, 1, n + 1) cout << visited[i] - 1 << '\n';
return 0;
}
# | 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... |