42572023-03-19 19:12:14nkdorka1212Hálózati átvitelcpp17Wrong answer 13/5028ms5384 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/2,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<=i)
           {
               velo[e[j].b].first=min(e[j].w,velo[e[j].a].first);
               velo[e[j].b].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<=i)
           {
               velo[e[j].a].first=min(e[j].w,velo[e[j].b].first);
               velo[e[j].a].second=velo[e[j].b].second+1;
           }
       }
        /*for(int i=1;i<=n;i++)
        {
            cout<<velo[i].first<<" "<<velo[i].second<<"\n";
        }
        cout<<"\n";*/
   }

}

int main()
{
    cin>>n>>m>>k>>h;
    e.resize(m+1);
    velo.resize(n+1,{0,-1});
    for(int i=1;i<=m;i++)
    {
        cin>>e[i].a>>e[i].b>>e[i].w;
    }/*
    for(edge x : e)
    {
        cout<<x.a<<" "<<x.b<<" "<<x.w<<"\n";
    }*/
    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

6 7 2 2
5 1 8
6 5 2
3 2 20
5 4 10
3 4 1
1 2 6
1 6 7

6 8 2 2
5 1 8
6 5 2
3 2 20
5 4 10
3 4 1
1 2 6
1 6 7
4 2 30

*/
SubtaskSumTestVerdictTimeMemory
base13/50
1Accepted0/03ms2064 KiB
2Wrong answer0/03ms2084 KiB
3Wrong answer0/13ms2288 KiB
4Wrong answer0/13ms2500 KiB
5Wrong answer0/23ms2588 KiB
6Accepted2/23ms2616 KiB
7Wrong answer0/23ms2720 KiB
8Wrong answer0/23ms2936 KiB
9Wrong answer0/14ms3176 KiB
10Wrong answer0/14ms3256 KiB
11Accepted1/16ms3396 KiB
12Wrong answer0/17ms3960 KiB
13Wrong answer0/26ms3632 KiB
14Wrong answer0/27ms3904 KiB
15Wrong answer0/212ms4048 KiB
16Wrong answer0/210ms4044 KiB
17Wrong answer0/210ms4048 KiB
18Accepted2/212ms4180 KiB
19Accepted2/212ms4384 KiB
20Accepted2/210ms4404 KiB
21Wrong answer0/113ms4708 KiB
22Wrong answer0/117ms4556 KiB
23Wrong answer0/120ms4680 KiB
24Wrong answer0/124ms4676 KiB
25Accepted2/228ms4676 KiB
26Wrong answer0/228ms4684 KiB
27Accepted2/228ms5004 KiB
28Wrong answer0/224ms4952 KiB
29Wrong answer0/225ms5080 KiB
30Wrong answer0/224ms5384 KiB
31Wrong answer0/224ms5340 KiB
32Wrong answer0/225ms5336 KiB