211192026-01-12 12:04:23csdavidHálózati átvitelcpp17Accepted 50/50157ms5480 KiB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct node{
    int maxi=-1;
    int speed[101] = {-1};
    vector<pair<int, int>> szomszed;
};

node a[10000];
int n, k, h;
void bejar(int x, int tav){
    a[x].maxi=max(a[x].maxi, a[x].speed[tav]);
    if(tav==h){
        return;
    }
    //cout << "\n\nx: " << x << "\ntav: " << tav;
    for(pair<int, int> i: a[x].szomszed){
        if(x==3&&i.first==2){
            //cout << "\n\na[x].speed[tav]: " << a[x].speed[tav];
            //cout << "a[i.first].speed[tav+1]): " << a[i.first].speed[tav+1];
        }
        if(min(a[x].speed[tav], i.second)>a[i.first].speed[tav+1]){
            a[i.first].speed[tav+1]=min(a[x].speed[tav], i.second);
            bejar(i.first, tav+1);
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, b, c, y, m, x, tav;
    cin >> n >> m >> k >> h;
    k--;
    while(m--){
        cin >> b >> c >> y;
        b--;
        c--;
        a[c].szomszed.push_back(make_pair(b, y));
        a[b].szomszed.push_back(make_pair(c, y));
    }
    a[k].speed[0]=9999999;
    queue<pair<int, int>> q;
    q.push(make_pair(k, 0));
    while(!q.empty()){
        x=q.front().first;
        tav=q.front().second;
        q.pop();
        a[x].maxi=max(a[x].maxi, a[x].speed[tav]);
        //cout << x << ' ' << tav << '\n';
        if(tav!=h){
            for(pair<int, int> i: a[x].szomszed){
                if(min(a[x].speed[tav], i.second)>a[i.first].speed[tav+1]){
                    a[i.first].speed[tav+1]=min(a[x].speed[tav], i.second);
                    q.push(make_pair(i.first, tav+1));
                }
            }
        }

    }





    a[k].maxi=0;
    for(int i=0; i<n; i++){
        cout << a[i].maxi << '\n';
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/04ms4608 KiB
2Accepted0/04ms4660 KiB
3Accepted1/14ms4404 KiB
4Accepted1/14ms4404 KiB
5Accepted2/24ms4404 KiB
6Accepted2/24ms4844 KiB
7Accepted2/24ms4660 KiB
8Accepted2/24ms4664 KiB
9Accepted1/16ms4660 KiB
10Accepted1/17ms4732 KiB
11Accepted1/113ms4660 KiB
12Accepted1/112ms4668 KiB
13Accepted2/210ms4748 KiB
14Accepted2/212ms4804 KiB
15Accepted2/224ms5240 KiB
16Accepted2/217ms4992 KiB
17Accepted2/219ms5004 KiB
18Accepted2/228ms4976 KiB
19Accepted2/224ms4752 KiB
20Accepted2/220ms4916 KiB
21Accepted1/146ms4924 KiB
22Accepted1/174ms5236 KiB
23Accepted1/197ms5152 KiB
24Accepted1/1120ms5404 KiB
25Accepted2/2144ms5428 KiB
26Accepted2/2143ms5480 KiB
27Accepted2/2157ms5444 KiB
28Accepted2/248ms5428 KiB
29Accepted2/254ms5428 KiB
30Accepted2/252ms5368 KiB
31Accepted2/250ms5172 KiB
32Accepted2/256ms5248 KiB