13252022-05-13 19:30:05nkdorka1212Hálózati átvitelcpp11Wrong answer 18/5048ms7884 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;
vector<bool>rewrote;

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

int main()
{
    cin>>n>>m>>k>>h;
    velocity.resize(n+1,-1);
    g.resize(n+1);
    pos.resize(n+1);
    rewrote.resize(n+1,0);
    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

4 5 1 2
1 3 1
1 2 1
2 3 3
3 4 3
1 4 3

*/
SubtaskSumTestVerdictTimeMemory
base18/50
1Accepted0/02ms1852 KiB
2Wrong answer0/01ms1928 KiB
3Accepted1/11ms1916 KiB
4Wrong answer0/11ms1928 KiB
5Wrong answer0/22ms1928 KiB
6Accepted2/22ms1956 KiB
7Wrong answer0/22ms1992 KiB
8Wrong answer0/22ms1996 KiB
9Wrong answer0/13ms2044 KiB
10Accepted1/14ms2152 KiB
11Accepted1/14ms2280 KiB
12Wrong answer0/16ms2392 KiB
13Wrong answer0/24ms2444 KiB
14Wrong answer0/26ms2612 KiB
15Wrong answer0/212ms3012 KiB
16Wrong answer0/212ms3132 KiB
17Wrong answer0/212ms3272 KiB
18Accepted2/213ms3404 KiB
19Accepted2/212ms3544 KiB
20Accepted2/210ms3664 KiB
21Accepted1/124ms4116 KiB
22Wrong answer0/128ms4680 KiB
23Accepted1/132ms5004 KiB
24Accepted1/137ms5288 KiB
25Accepted2/246ms5912 KiB
26Wrong answer0/246ms6164 KiB
27Accepted2/248ms6552 KiB
28Wrong answer0/228ms6776 KiB
29Wrong answer0/229ms7060 KiB
30Wrong answer0/228ms7324 KiB
31Wrong answer0/227ms7592 KiB
32Wrong answer0/228ms7884 KiB