13262022-05-13 20:41:28nkdorka1212Logisztikai központcpp11Wrong answer 0/501.057s17532 KiB
#include <bits/stdc++.h>

using namespace std;

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

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(velocity2[j],x.second)&& !rewrote[j])
                {
                    velocity[x.first]=min(velocity2[j],x.second);
                    //rewrote[x.first]=true;
                }
            }
        }
        velocity2=velocity;
    }
}

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

6 8 1 3
1 3 1
1 2 1
2 3 3
3 4 3
1 4 3
1 5 5
5 6 5
2 6 5

7 9 2 3
2 1 2
2 4 4
2 4 4
1 3 3
3 5 2
4 5 3
4 6 5
6 7 8
1 7 9

3 2 1 1
1 2 4
2 3 4

4 5 1 2
1 2 3
1 3 2
1 4 1
2 3 3
3 4 2
*/
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/02ms1832 KiB
2Time limit exceeded0/01.044s8268 KiB
3Wrong answer0/41ms3428 KiB
4Wrong answer0/41ms3440 KiB
5Wrong answer0/41ms3444 KiB
6Wrong answer0/42ms3456 KiB
7Wrong answer0/42ms3464 KiB
8Wrong answer0/57ms3488 KiB
9Time limit exceeded0/21.026s10376 KiB
10Wrong answer0/2135ms12296 KiB
11Wrong answer0/243ms5256 KiB
12Wrong answer0/22ms5316 KiB
13Wrong answer0/2319ms5992 KiB
14Time limit exceeded0/21.021s5196 KiB
15Time limit exceeded0/21.037s7784 KiB
16Time limit exceeded0/21.057s10204 KiB
17Time limit exceeded0/21.046s11316 KiB
18Wrong answer0/290ms17532 KiB
19Time limit exceeded0/21.016s13488 KiB
20Wrong answer0/314ms11656 KiB