96672024-02-23 20:23:43Vkrisztian01Hálózati átvitelcpp17Accepted 50/5045ms6496 KiB
#include <iostream>
#include<algorithm>
#include<vector>

using namespace std;

int n,m,k,h,a,b,c;
vector<vector<pair<int,int> > > g;
vector<int>cost1;
vector<int>cost2;

void f()
{
    while(h--)
    {
        for(int node=1;node<=n;node++)
        {
            for(auto to:g[node])
            {
                cost2[to.first]=max(cost2[to.first],min(to.second,cost1[node]));
            }
        }
        cost1=cost2;
    }
}

int main()
{
    cin>>n>>m>>k>>h;
    g.resize(n+1);
    cost1.assign(n+1,-1);
    cost2.assign(n+1,-1);
    while(m--)
    {
        cin>>a>>b>>c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    cost1[k]=1e9;
    cost2[k]=1e9;
    f();
    cost1[k]=0;
    for(int i=1;i<=n;i++) cout<<cost1[i]<<"\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1876 KiB
2Accepted0/03ms2132 KiB
3Accepted1/13ms2344 KiB
4Accepted1/13ms2512 KiB
5Accepted2/23ms2760 KiB
6Accepted2/23ms2980 KiB
7Accepted2/23ms3340 KiB
8Accepted2/23ms3412 KiB
9Accepted1/14ms3740 KiB
10Accepted1/14ms4072 KiB
11Accepted1/16ms4136 KiB
12Accepted1/18ms4248 KiB
13Accepted2/26ms4288 KiB
14Accepted2/28ms4192 KiB
15Accepted2/213ms4444 KiB
16Accepted2/212ms4592 KiB
17Accepted2/213ms4564 KiB
18Accepted2/214ms4760 KiB
19Accepted2/213ms4844 KiB
20Accepted2/213ms5152 KiB
21Accepted1/124ms5808 KiB
22Accepted1/128ms5932 KiB
23Accepted1/132ms5856 KiB
24Accepted1/135ms6220 KiB
25Accepted2/243ms6348 KiB
26Accepted2/241ms6396 KiB
27Accepted2/245ms6460 KiB
28Accepted2/229ms6352 KiB
29Accepted2/230ms6348 KiB
30Accepted2/229ms6348 KiB
31Accepted2/229ms6348 KiB
32Accepted2/230ms6496 KiB