이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
/*
const int MOD = ;
inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}
inline void add(int &x, int y) {
    x += y;
    mod(x);
}
inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}
inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}
*/
using namespace std;
const int MAXN = (int) 1e5;
vector <int> g[MAXN + 1];
ll dst[MAXN + 1];
bool vis[MAXN + 1], check[MAXN + 1];
int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, m, k, a, b;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m >> k >> a >> b;
    for(i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    memset(dst, 0x3f, sizeof(dst));
    if(a <= b) {
        queue <int> Q;
        Q.push(k);
        dst[k] = 0;
        while(Q.size()) {
            int nod = Q.front();
            Q.pop();
            for(auto it : g[nod]) {
                if(dst[it] > dst[nod] + 1) {
                    dst[it] = dst[nod] + 1;
                    Q.push(it);
                }
            }
        }
        for(i = 1; i <= n; i++) {
            cout << 1LL * min(2 * a, b) * (dst[i] / 2) + (dst[i] & 1) * a << "\n";
        }
        return 0;
    }
    priority_queue < pair <ll, int> > pq;
    pq.push({0, k});
    while(pq.size()) {
        auto cur = pq.top();
        pq.pop();
        if(vis[cur.second]) {
            continue;
        }
        vis[cur.second] = 1;
        dst[cur.second] = -cur.first;
        for(auto it : g[cur.second]) {
            check[it] = 1;
            if(dst[it] > a - cur.first) {
                dst[it] = a - cur.first;
                pq.push({-dst[it], it});
            }
        }
        if(2 * a > b) {
            for(auto it : g[cur.second]) {
                for(auto itr : g[it]) {
                    if(check[itr] == 0 && dst[itr] > b - cur.first) {
                        dst[itr] = b - cur.first;
                        pq.push({-dst[itr], itr});
                    }
                }
            }
        }
        for(auto it : g[cur.second]) {
            check[it] = 0;
        }
    }
    for(i = 1; i <= n; i++) {
        cout << dst[i] << "\n";
    }
    //cin.close();
    //cout.close();
    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... |