13242022-05-13 19:14:16nkdorka1212Hálózati átvitelcpp11Wrong answer 6/5043ms7864 KiB
#include <bits/stdc++.h>

using namespace std;

int n,m,k,h;
vector<vector<pair<int,int>>>g;
vector<int>velocity;
vector<bool>pos;

void bellmann_ford()
{
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(auto x:g[j])
            {
                if(velocity[x.first]<min(velocity[j],x.second))
                {
                    velocity[x.first]=min(velocity[j],x.second);
                }
            }
        }
    }
}

int main()
{
    cin>>n>>m>>k>>h;
    velocity.resize(n+1,-1);
    g.resize(n+1);
    pos.resize(n+1);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        cin>>u>>v>>w;
        g[u].push_back({v,w});
        g[v].push_back({u,w});
    }
    velocity[k]=INT_MAX;
    bellmann_ford();
    for(int i=1;i<=n;i++)
    {
        if(i==k)
        {
            cout<<0<<'\n';
        }else
        {
            cout<<velocity[i]<<'\n';
        }
    }
    return 0;
}

/*4 6 2 2
1 2 1
2 3 1
2 4 1
1 3 1
1 4 5
3 4 5
*/
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/02ms1840 KiB
2Wrong answer0/02ms1920 KiB
3Wrong answer0/11ms1916 KiB
4Wrong answer0/11ms1916 KiB
5Wrong answer0/21ms1932 KiB
6Wrong answer0/22ms1944 KiB
7Wrong answer0/22ms1964 KiB
8Wrong answer0/22ms1988 KiB
9Wrong answer0/13ms2024 KiB
10Wrong answer0/14ms2056 KiB
11Accepted1/14ms2276 KiB
12Wrong answer0/16ms2492 KiB
13Wrong answer0/24ms2400 KiB
14Wrong answer0/26ms2612 KiB
15Wrong answer0/210ms2936 KiB
16Wrong answer0/210ms3060 KiB
17Wrong answer0/210ms3200 KiB
18Wrong answer0/212ms3328 KiB
19Wrong answer0/213ms3464 KiB
20Wrong answer0/227ms3596 KiB
21Accepted1/120ms4008 KiB
22Wrong answer0/127ms4656 KiB
23Accepted1/132ms4972 KiB
24Accepted1/137ms5276 KiB
25Wrong answer0/241ms5856 KiB
26Wrong answer0/241ms6136 KiB
27Accepted2/243ms6412 KiB
28Wrong answer0/237ms6728 KiB
29Wrong answer0/228ms7000 KiB
30Wrong answer0/227ms7280 KiB
31Wrong answer0/226ms7544 KiB
32Wrong answer0/228ms7864 KiB