211202026-01-12 12:09:02csdavidHálózati átvitelcpp17Time limit exceeded 37/50601ms13668 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);
        }
    }
}*/

class Compare {
public:
    bool operator()(pair<int, int> x, pair<int, int> y)
    {
        if (a[x.first].speed[y.second] < a[y.first].speed[y.second]){
            return true;
        }
        return false;
    }
};

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;
    priority_queue<pair<int, int>, vector<pair<int, int>>, Compare> q;
    q.push(make_pair(k, 0));
    while(!q.empty()){
        x=q.top().first;
        tav=q.top().second;
        q.pop();
        a[x].maxi=max(a[x].maxi, a[x].speed[tav]);
        //cout << x << ' ' << a[x].speed[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
base37/50
1Accepted0/04ms4464 KiB
2Accepted0/04ms4844 KiB
3Accepted1/14ms4404 KiB
4Accepted1/14ms4404 KiB
5Accepted2/24ms4836 KiB
6Accepted2/26ms4704 KiB
7Accepted2/26ms4660 KiB
8Accepted2/24ms4660 KiB
9Accepted1/17ms4624 KiB
10Accepted1/116ms4920 KiB
11Accepted1/132ms5320 KiB
12Accepted1/126ms5204 KiB
13Accepted2/235ms5376 KiB
14Accepted2/235ms5440 KiB
15Accepted2/286ms6064 KiB
16Accepted2/250ms6064 KiB
17Accepted2/268ms6080 KiB
18Accepted2/2119ms6960 KiB
19Accepted2/296ms6064 KiB
20Accepted2/268ms5864 KiB
21Accepted1/1314ms7096 KiB
22Time limit exceeded0/1588ms9108 KiB
23Time limit exceeded0/1600ms9400 KiB
24Time limit exceeded0/1601ms13464 KiB
25Time limit exceeded0/2584ms13464 KiB
26Time limit exceeded0/2587ms13464 KiB
27Time limit exceeded0/2601ms13552 KiB
28Accepted2/2481ms13472 KiB
29Time limit exceeded0/2568ms13468 KiB
30Accepted2/2546ms13468 KiB
31Accepted2/2522ms13668 KiB
32Time limit exceeded0/2559ms13480 KiB