13232022-05-13 19:03:34nkdorka1212Hálózati átvitelcpp11Wrong answer 0/5043ms7820 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,-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
base0/50
1Accepted0/02ms1856 KiB
2Wrong answer0/02ms1864 KiB
3Wrong answer0/11ms1928 KiB
4Wrong answer0/11ms1928 KiB
5Wrong answer0/22ms1936 KiB
6Wrong answer0/22ms1956 KiB
7Wrong answer0/22ms1976 KiB
8Wrong answer0/23ms2000 KiB
9Wrong answer0/12ms2036 KiB
10Wrong answer0/13ms2072 KiB
11Wrong answer0/14ms2280 KiB
12Wrong answer0/16ms2368 KiB
13Wrong answer0/24ms2408 KiB
14Wrong answer0/26ms2616 KiB
15Wrong answer0/212ms2944 KiB
16Wrong answer0/210ms3124 KiB
17Wrong answer0/210ms3208 KiB
18Wrong answer0/212ms3400 KiB
19Wrong answer0/29ms3468 KiB
20Wrong answer0/29ms3604 KiB
21Wrong answer0/119ms4020 KiB
22Wrong answer0/125ms4664 KiB
23Wrong answer0/132ms4980 KiB
24Wrong answer0/143ms5208 KiB
25Wrong answer0/241ms5864 KiB
26Wrong answer0/237ms6148 KiB
27Wrong answer0/243ms6420 KiB
28Wrong answer0/225ms6732 KiB
29Wrong answer0/228ms7012 KiB
30Wrong answer0/239ms7288 KiB
31Wrong answer0/225ms7552 KiB
32Wrong answer0/228ms7820 KiB