#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(vis[nx]) 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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
1516 KB |
Output is correct |
2 |
Correct |
7 ms |
1364 KB |
Output is correct |
3 |
Incorrect |
10 ms |
1444 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2150 ms |
4112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2286 ms |
6784 KB |
Output is correct |
2 |
Correct |
29 ms |
5980 KB |
Output is correct |
3 |
Incorrect |
51 ms |
6604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3692 ms |
8060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2273 ms |
9396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
566 ms |
8748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
8940 KB |
Output is correct |
2 |
Correct |
53 ms |
8900 KB |
Output is correct |
3 |
Incorrect |
64 ms |
8828 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |