210972026-01-12 11:37:27csdavidHálózati átvitelcpp17Time limit exceeded 36/50600ms5428 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;
    bejar(k, 0);
    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]);
        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));
                }
            }
        }

    }





    a[k].maxi=0;
    for(int i=0; i<n; i++){
        cout << a[i].maxi << '\n';
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base36/50
1Accepted0/04ms4404 KiB
2Accepted0/04ms4660 KiB
3Accepted1/14ms4844 KiB
4Accepted1/14ms4404 KiB
5Accepted2/24ms4660 KiB
6Accepted2/24ms4660 KiB
7Accepted2/24ms4688 KiB
8Accepted2/24ms4660 KiB
9Accepted1/16ms4660 KiB
10Accepted1/18ms4476 KiB
11Accepted1/119ms4516 KiB
12Accepted1/116ms4596 KiB
13Accepted2/218ms4752 KiB
14Accepted2/224ms4816 KiB
15Accepted2/263ms4916 KiB
16Accepted2/230ms4748 KiB
17Accepted2/243ms4888 KiB
18Accepted2/279ms4932 KiB
19Accepted2/264ms4916 KiB
20Accepted2/243ms4932 KiB
21Accepted1/1157ms4956 KiB
22Accepted1/1374ms5096 KiB
23Accepted1/1372ms5188 KiB
24Accepted1/1527ms5212 KiB
25Time limit exceeded0/2583ms5364 KiB
26Time limit exceeded0/2579ms5172 KiB
27Time limit exceeded0/2580ms5172 KiB
28Accepted2/2442ms5428 KiB
29Time limit exceeded0/2586ms5172 KiB
30Time limit exceeded0/2591ms5172 KiB
31Time limit exceeded0/2578ms5172 KiB
32Time limit exceeded0/2600ms5172 KiB