44612023-03-28 11:37:271478Hálózati átvitelcpp17Wrong answer 1/50196ms30980 KiB
#include <bits/stdc++.h>

using namespace std;

struct el{
    int k, v, e;
};

struct compare{
    bool operator()(el p1, el p2)
    {
        return p1.e < p2.e;
    }
};

int main()
{
    //ifstream cin("in.txt");

    int n, m, k, h;
    cin >> n >> m >> k >> h;

    vector<vector<el>> sz(n+1);

    for(int i=1; i<=m; i++){
        el a;
        cin>>a.k>>a.v>>a.e;

        sz[a.k].push_back(a);

        swap(a.k, a.v);
        sz[a.k].push_back(a);
    }

    priority_queue <el, vector<el>, compare> elek;

    for(el x:sz[k]) elek.push(x);

    vector<int> ans(n + 1, -1);
    vector<pair<int, int>> akt(n + 1);
    vector<bool> lattam(n+1);
    lattam[k] = 1;
    ans[k] = 1e5+1;
    while(!elek.empty()){
        el x;
        x = elek.top();
        elek.pop();

         if(akt[x.k].second + 1 <= h && !lattam[x.v]){
            akt[x.v].first = min(ans[x.k], x.e);
            akt[x.v].second = akt[x.k].second + 1;

            if(ans[x.v] == -1){
                ans[x.v] = max(akt[x.v].first, ans[x.v]);
            }

            lattam[x.v] = 1;
            for(el y:sz[x.v]) {
                if(!lattam[y.v]){
                    elek.push(y);
                }
            }
        }
        else{
            lattam[x.k] = 0;
        }
    }
    ans[k] = 0;
    for(int i = 1; i <= n; i++){
        cout << ans[i] << '\n';
    }













    return 0;
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Accepted0/03ms1812 KiB
2Wrong answer0/03ms2080 KiB
3Accepted1/13ms2280 KiB
4Wrong answer0/13ms2360 KiB
5Wrong answer0/23ms2576 KiB
6Wrong answer0/23ms2932 KiB
7Wrong answer0/27ms3124 KiB
8Wrong answer0/28ms3384 KiB
9Wrong answer0/14ms3468 KiB
10Wrong answer0/14ms3744 KiB
11Wrong answer0/17ms3912 KiB
12Wrong answer0/19ms4468 KiB
13Wrong answer0/27ms4164 KiB
14Wrong answer0/28ms4320 KiB
15Wrong answer0/216ms4908 KiB
16Wrong answer0/217ms5040 KiB
17Wrong answer0/217ms5032 KiB
18Wrong answer0/216ms5032 KiB
19Wrong answer0/216ms5032 KiB
20Wrong answer0/216ms5132 KiB
21Wrong answer0/114ms5260 KiB
22Wrong answer0/118ms5736 KiB
23Wrong answer0/123ms6296 KiB
24Wrong answer0/126ms6432 KiB
25Wrong answer0/227ms6676 KiB
26Wrong answer0/227ms6464 KiB
27Wrong answer0/229ms6700 KiB
28Wrong answer0/2143ms30872 KiB
29Wrong answer0/2184ms30820 KiB
30Wrong answer0/2192ms30840 KiB
31Wrong answer0/2196ms30972 KiB
32Wrong answer0/2171ms30980 KiB