13222022-05-13 19:02:27nkdorka1212Hálózati átvitelcpp11Wrong answer 0/5041ms7816 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[i],x.second))
                {
                    velocity[x.first]=min(velocity[i],x.second);
                }
            }
        }
    }
}

int main()
{
    cin>>n>>m>>k>>h;
    velocity.resize(n+1,0);
    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
base0/50
1Accepted0/02ms1848 KiB
2Wrong answer0/02ms1864 KiB
3Wrong answer0/11ms1928 KiB
4Wrong answer0/11ms1920 KiB
5Wrong answer0/21ms1932 KiB
6Wrong answer0/21ms1952 KiB
7Wrong answer0/22ms1976 KiB
8Wrong answer0/22ms1992 KiB
9Wrong answer0/12ms2028 KiB
10Wrong answer0/14ms2068 KiB
11Wrong answer0/16ms2288 KiB
12Wrong answer0/17ms2500 KiB
13Wrong answer0/24ms2408 KiB
14Wrong answer0/26ms2484 KiB
15Wrong answer0/212ms2944 KiB
16Wrong answer0/210ms3080 KiB
17Wrong answer0/214ms3208 KiB
18Wrong answer0/213ms3344 KiB
19Wrong answer0/210ms3472 KiB
20Wrong answer0/29ms3604 KiB
21Wrong answer0/119ms4020 KiB
22Wrong answer0/126ms4664 KiB
23Wrong answer0/132ms4980 KiB
24Wrong answer0/132ms5208 KiB
25Wrong answer0/237ms5868 KiB
26Wrong answer0/239ms6144 KiB
27Wrong answer0/241ms6552 KiB
28Wrong answer0/224ms6664 KiB
29Wrong answer0/228ms7012 KiB
30Wrong answer0/226ms7284 KiB
31Wrong answer0/227ms7556 KiB
32Wrong answer0/228ms7816 KiB