42522023-03-19 17:42:13nkdorka1212Hálózati átvitelcpp17Wrong answer 0/5037ms5588 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
base0/50
1Wrong answer0/03ms1880 KiB
2Wrong answer0/03ms2076 KiB
3Wrong answer0/13ms2280 KiB
4Wrong answer0/13ms2492 KiB
5Wrong answer0/23ms2708 KiB
6Wrong answer0/23ms2948 KiB
7Wrong answer0/24ms3140 KiB
8Wrong answer0/24ms3372 KiB
9Wrong answer0/14ms3592 KiB
10Wrong answer0/14ms3808 KiB
11Wrong answer0/17ms4128 KiB
12Wrong answer0/18ms4136 KiB
13Wrong answer0/27ms4152 KiB
14Wrong answer0/28ms4500 KiB
15Wrong answer0/216ms4576 KiB
16Wrong answer0/214ms4572 KiB
17Wrong answer0/214ms4568 KiB
18Wrong answer0/216ms4820 KiB
19Wrong answer0/216ms4912 KiB
20Wrong answer0/214ms4736 KiB
21Wrong answer0/117ms5160 KiB
22Wrong answer0/124ms5020 KiB
23Wrong answer0/128ms5148 KiB
24Wrong answer0/130ms5148 KiB
25Wrong answer0/235ms5400 KiB
26Wrong answer0/235ms5364 KiB
27Wrong answer0/237ms5368 KiB
28Wrong answer0/232ms5336 KiB
29Wrong answer0/234ms5396 KiB
30Wrong answer0/232ms5588 KiB
31Wrong answer0/230ms5456 KiB
32Wrong answer0/232ms5388 KiB