42502023-03-19 16:25:36nkdorka1212Hálózati átvitelcpp17Runtime error 0/5020ms5312 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/03ms1748 KiB
2Runtime error0/03ms2092 KiB
3Runtime error0/13ms2344 KiB
4Runtime error0/13ms2560 KiB
5Runtime error0/23ms2780 KiB
6Runtime error0/23ms3184 KiB
7Runtime error0/23ms3396 KiB
8Runtime error0/23ms3444 KiB
9Runtime error0/14ms3632 KiB
10Runtime error0/14ms3736 KiB
11Runtime error0/14ms4020 KiB
12Runtime error0/17ms4060 KiB
13Runtime error0/26ms4168 KiB
14Runtime error0/27ms4288 KiB
15Runtime error0/210ms4208 KiB
16Runtime error0/210ms4212 KiB
17Runtime error0/210ms4236 KiB
18Runtime error0/210ms4468 KiB
19Runtime error0/210ms4568 KiB
20Runtime error0/210ms4424 KiB
21Runtime error0/19ms4604 KiB
22Runtime error0/113ms4648 KiB
23Runtime error0/116ms4688 KiB
24Runtime error0/117ms4836 KiB
25Runtime error0/218ms4852 KiB
26Runtime error0/218ms4844 KiB
27Runtime error0/220ms4872 KiB
28Runtime error0/219ms4988 KiB
29Runtime error0/218ms5076 KiB
30Runtime error0/218ms5064 KiB
31Runtime error0/218ms5156 KiB
32Runtime error0/219ms5312 KiB