44862023-03-28 15:27:01UnluckYHálózati átvitelcpp11Accepted 50/50549ms39792 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

ll INF = 100001;

int main(){

    int n, m, k, h; cin >> n >> m >> k >> h;
    vector<vector<pair<int, int>>> v(n+1);

    for (int i = 0; i < m; i++){
        int a, b, c; cin >> a >> b >> c;
        v[a].push_back({b, c});
        v[b].push_back({a, c});
    } 

    vector<vector<int>> d(n+1, vector<int>(h+1, 0));
    priority_queue<pair<int, pair<int, int>>> q;
    q.push({INF, {k, 0}});
    d[k][0] = INF;

    while(!q.empty()){
        int dis = q.top().first;
        int x = q.top().second.first;
        int y = q.top().second.second;
        q.pop();
        if (dis < d[x][y] || y >= h) continue;

        for (pair<int, int> i : v[x]){
            if (min(dis, i.second) > d[i.first][y+1]){
                d[i.first][y+1] = min(dis, i.second);
                q.push({d[i.first][y+1], {i.first, y+1}});
            }
        }
    }

    vector<int> dd(n+1, 0);

    //cout << d[3][2] << endl;

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= h; j++){
            dd[i] = max(dd[i], d[i][j]);
        }
    }

    dd[k] = 0;



    for (int i = 1; i <= n; i++){
        if (dd[i] == 0 && i != k){
            cout << -1 << endl; continue;
        }
        cout << dd[i] << endl;}

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2084 KiB
2Accepted0/03ms2180 KiB
3Accepted1/13ms2368 KiB
4Accepted1/13ms2384 KiB
5Accepted2/23ms2496 KiB
6Accepted2/24ms2880 KiB
7Accepted2/24ms3196 KiB
8Accepted2/24ms3320 KiB
9Accepted1/16ms3848 KiB
10Accepted1/112ms4312 KiB
11Accepted1/120ms5084 KiB
12Accepted1/117ms5112 KiB
13Accepted2/220ms5076 KiB
14Accepted2/221ms5220 KiB
15Accepted2/254ms7968 KiB
16Accepted2/232ms6616 KiB
17Accepted2/241ms6856 KiB
18Accepted2/267ms8748 KiB
19Accepted2/252ms8760 KiB
20Accepted2/241ms7116 KiB
21Accepted1/1164ms14848 KiB
22Accepted1/1237ms19280 KiB
23Accepted1/1307ms25488 KiB
24Accepted1/1377ms25852 KiB
25Accepted2/2486ms27500 KiB
26Accepted2/2486ms27424 KiB
27Accepted2/2549ms39792 KiB
28Accepted2/2384ms38184 KiB
29Accepted2/2437ms39776 KiB
30Accepted2/2458ms39676 KiB
31Accepted2/2407ms39484 KiB
32Accepted2/2449ms39604 KiB