211202026-01-12 12:09:02csdavidHálózati átvitelcpp17Időlimit túllépés 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base37/50
1Elfogadva0/04ms4464 KiB
2Elfogadva0/04ms4844 KiB
3Elfogadva1/14ms4404 KiB
4Elfogadva1/14ms4404 KiB
5Elfogadva2/24ms4836 KiB
6Elfogadva2/26ms4704 KiB
7Elfogadva2/26ms4660 KiB
8Elfogadva2/24ms4660 KiB
9Elfogadva1/17ms4624 KiB
10Elfogadva1/116ms4920 KiB
11Elfogadva1/132ms5320 KiB
12Elfogadva1/126ms5204 KiB
13Elfogadva2/235ms5376 KiB
14Elfogadva2/235ms5440 KiB
15Elfogadva2/286ms6064 KiB
16Elfogadva2/250ms6064 KiB
17Elfogadva2/268ms6080 KiB
18Elfogadva2/2119ms6960 KiB
19Elfogadva2/296ms6064 KiB
20Elfogadva2/268ms5864 KiB
21Elfogadva1/1314ms7096 KiB
22Időlimit túllépés0/1588ms9108 KiB
23Időlimit túllépés0/1600ms9400 KiB
24Időlimit túllépés0/1601ms13464 KiB
25Időlimit túllépés0/2584ms13464 KiB
26Időlimit túllépés0/2587ms13464 KiB
27Időlimit túllépés0/2601ms13552 KiB
28Elfogadva2/2481ms13472 KiB
29Időlimit túllépés0/2568ms13468 KiB
30Elfogadva2/2546ms13468 KiB
31Elfogadva2/2522ms13668 KiB
32Időlimit túllépés0/2559ms13480 KiB