44862023-03-28 15:27:01UnluckYHálózati átvitelcpp11Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms2084 KiB
2Elfogadva0/03ms2180 KiB
3Elfogadva1/13ms2368 KiB
4Elfogadva1/13ms2384 KiB
5Elfogadva2/23ms2496 KiB
6Elfogadva2/24ms2880 KiB
7Elfogadva2/24ms3196 KiB
8Elfogadva2/24ms3320 KiB
9Elfogadva1/16ms3848 KiB
10Elfogadva1/112ms4312 KiB
11Elfogadva1/120ms5084 KiB
12Elfogadva1/117ms5112 KiB
13Elfogadva2/220ms5076 KiB
14Elfogadva2/221ms5220 KiB
15Elfogadva2/254ms7968 KiB
16Elfogadva2/232ms6616 KiB
17Elfogadva2/241ms6856 KiB
18Elfogadva2/267ms8748 KiB
19Elfogadva2/252ms8760 KiB
20Elfogadva2/241ms7116 KiB
21Elfogadva1/1164ms14848 KiB
22Elfogadva1/1237ms19280 KiB
23Elfogadva1/1307ms25488 KiB
24Elfogadva1/1377ms25852 KiB
25Elfogadva2/2486ms27500 KiB
26Elfogadva2/2486ms27424 KiB
27Elfogadva2/2549ms39792 KiB
28Elfogadva2/2384ms38184 KiB
29Elfogadva2/2437ms39776 KiB
30Elfogadva2/2458ms39676 KiB
31Elfogadva2/2407ms39484 KiB
32Elfogadva2/2449ms39604 KiB