44562023-03-28 11:18:261478Hálózati átvitelcpp17Wrong answer 0/503ms5064 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(ans[x.v] == -1 && akt[x.k].second + 1 <= h && !lattam[x.v]){
            akt[x.v].first = min(ans[x.k], x.e);
            ans[x.v] = max(akt[x.v].first, ans[x.v]);
            akt[x.v].second = akt[x.k].second+1;
            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
base0/50
1Wrong answer0/03ms1808 KiB
2Wrong answer0/02ms2056 KiB
3Wrong answer0/13ms2264 KiB
4Wrong answer0/13ms2480 KiB
5Wrong answer0/23ms2692 KiB
6Wrong answer0/23ms2892 KiB
7Wrong answer0/23ms3052 KiB
8Wrong answer0/22ms3268 KiB
9Wrong answer0/12ms3248 KiB
10Wrong answer0/12ms3476 KiB
11Wrong answer0/13ms3740 KiB
12Wrong answer0/12ms3856 KiB
13Wrong answer0/23ms4048 KiB
14Wrong answer0/22ms4084 KiB
15Wrong answer0/23ms4264 KiB
16Wrong answer0/22ms4372 KiB
17Wrong answer0/22ms4352 KiB
18Wrong answer0/22ms4244 KiB
19Wrong answer0/22ms4476 KiB
20Wrong answer0/22ms4564 KiB
21Wrong answer0/12ms4460 KiB
22Wrong answer0/12ms4456 KiB
23Wrong answer0/13ms4640 KiB
24Wrong answer0/13ms4852 KiB
25Wrong answer0/22ms4888 KiB
26Wrong answer0/22ms4832 KiB
27Wrong answer0/23ms4836 KiB
28Wrong answer0/23ms4940 KiB
29Wrong answer0/22ms5064 KiB
30Wrong answer0/22ms4940 KiB
31Wrong answer0/22ms5064 KiB
32Wrong answer0/22ms4956 KiB