42492023-03-19 16:25:35nkdorka1212Hálózati átvitelcpp17Runtime error 0/5020ms5572 KiB
#include <bits/stdc++.h>

using namespace std;

struct edge
{
    int a,b,w;
};

int n,m,k,h;
vector<edge>e;
vector<pair<int,int>>velo; // {velo,distance}

void bellman_ford(int k)
{
   velo[k]={INT_MAX,0};
   for(int i=1;i<=h;i++)
   {
       for(int j=1;j<=m;j++)  //e[j].a,e[j].b
       {
           if(min(e[j].w,velo[e[j].a].first)> velo[e[j].b].first && velo[e[j].a].second+1 <h)
           {
               velo[e[j].b].first=min(e[j].w,velo[e[j].a].first);
               velo[e[j].w].second=velo[e[j].a].second+1;
           }
           if(min(e[j].w,velo[e[j].b].first)> velo[e[j].a].first && velo[e[j].b].second+1 <h)
           {
               velo[e[j].a].first=min(e[j].w,velo[e[j].b].first);
               velo[e[j].w].second=velo[e[j].b].second+1;
           }
       }
   }

}

int main()
{
    cin>>n>>m>>k>>h;
    e.resize(m+1);
    velo.resize(n+1,{0,0});
    for(int i=1;i<=m;i++)
    {
        cin>>e[i].a>>e[i].b>>e[i].w;
    }
    bellman_ford(k);
    velo[k].first=0;
    for(int i=1;i<=n;i++)
    {
        cout<<velo[i].first<<"\n";
    }

    return 0;
}


/*
5 6 5 2
1 2 2
1 5 4
1 3 2
1 4 3
5 4 1
5 3 4

*/
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/03ms1876 KiB
2Runtime error0/03ms2164 KiB
3Runtime error0/13ms2372 KiB
4Runtime error0/13ms2660 KiB
5Runtime error0/23ms2872 KiB
6Runtime error0/23ms3080 KiB
7Runtime error0/23ms2976 KiB
8Runtime error0/24ms3232 KiB
9Runtime error0/14ms3452 KiB
10Runtime error0/14ms3672 KiB
11Runtime error0/16ms3780 KiB
12Runtime error0/17ms4060 KiB
13Runtime error0/26ms4236 KiB
14Runtime error0/27ms4244 KiB
15Runtime error0/29ms4296 KiB
16Runtime error0/210ms4564 KiB
17Runtime error0/29ms4764 KiB
18Runtime error0/210ms4972 KiB
19Runtime error0/29ms4816 KiB
20Runtime error0/29ms4848 KiB
21Runtime error0/19ms5000 KiB
22Runtime error0/113ms5188 KiB
23Runtime error0/116ms5332 KiB
24Runtime error0/117ms5332 KiB
25Runtime error0/218ms5356 KiB
26Runtime error0/218ms5440 KiB
27Runtime error0/220ms5468 KiB
28Runtime error0/219ms5336 KiB
29Runtime error0/218ms5332 KiB
30Runtime error0/218ms5328 KiB
31Runtime error0/218ms5540 KiB
32Runtime error0/219ms5572 KiB