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;
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;
// and so on
vector<vector<int> > mp;
bool vis[100001];
int vis2[100001];
ll dist[100001];
const ll INF = 1LL << 60;
priority_queue<pll, vector<pll>, greater<pll> > pq;
int N, M, S, A, B;
void dijkstra() {
for (int i = 1; i <= N; i++) dist[i] = INF;
dist[S] = 0;
pq.push({dist[S], S});
while (!pq.empty()) {
auto [d, x] = pq.top();
pq.pop();
if (vis[x]) continue;
vis[x] = true;
vis2[x] = x;
for (auto nx : mp[x]) {
vis2[nx] = x;
if (!vis[nx] && dist[nx] > dist[x] + A) {
dist[nx] = dist[x] + A;
pq.push({dist[nx], nx});
}
}
for (auto nx : mp[x]) {
if(dist[nx]+A<dist[x]+B) continue;
for (auto nnx : mp[nx]) {
if (vis2[nnx] == x) continue;
vis2[nnx] = x;
if (!vis[nnx] && dist[nnx] > dist[x] + B) {
dist[nnx] = dist[x] + B;
pq.push({dist[nnx], nnx});
}
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M >> S >> A >> B;
mp.resize(N + 1);
vector<int> costs;
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
mp[a].push_back(b);
mp[b].push_back(a);
}
dijkstra();
for (int i = 1; i <= N; i++) cout << dist[i] << '\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... |