46962023-03-31 09:28:04Erik_GepardHálózati átvitelcpp17Wrong answer 0/5019ms7620 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

int n, m, h, start;
struct elek{
    int a;
    int b;
    int suly;
};
vector<elek> e;
void bellmann_ford(){
    vector<int> d(n+1, LLONG_MAX/100);
    d[start]=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<2*m; j++){
            if(d[e[j].a]<1e12){
                if(d[e[j].b]>d[e[j].a]+e[j].suly){
                    d[e[j].b]=d[e[j].a]+e[j].suly;
                }
            }
        }
    }
    for(int i=1; i<=n; i++){
        if(d[i]<1e12){
            cout<<d[i]<<"\n";
        }
        else{
            cout<<"-1\n";
        }
    }
}

void solve(){
    cin>>n>>m>>start>>h;
    for(int i=0; i<m; i++){
        int x, y, w;
        elek e1;
        cin>>x>>y>>w;
        e1.a=x;
        e1.b=y;
        e1.suly=w;
        e.push_back(e1);
        e1.a=y;
        e1.b=x;
        e1.suly=w;
        e.push_back(e1);
    }
    bellmann_ford();
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1832 KiB
2Wrong answer0/03ms2192 KiB
3Wrong answer0/13ms2344 KiB
4Wrong answer0/13ms2696 KiB
5Wrong answer0/23ms2808 KiB
6Wrong answer0/23ms3056 KiB
7Wrong answer0/23ms3312 KiB
8Wrong answer0/23ms3432 KiB
9Wrong answer0/13ms3536 KiB
10Wrong answer0/13ms3532 KiB
11Wrong answer0/14ms4016 KiB
12Wrong answer0/14ms4392 KiB
13Wrong answer0/24ms4084 KiB
14Wrong answer0/24ms4388 KiB
15Wrong answer0/28ms5456 KiB
16Wrong answer0/27ms5680 KiB
17Wrong answer0/27ms5624 KiB
18Wrong answer0/28ms5616 KiB
19Wrong answer0/28ms5620 KiB
20Wrong answer0/27ms5896 KiB
21Wrong answer0/112ms5856 KiB
22Wrong answer0/113ms5780 KiB
23Wrong answer0/114ms5860 KiB
24Wrong answer0/116ms7344 KiB
25Wrong answer0/218ms7616 KiB
26Wrong answer0/217ms7524 KiB
27Wrong answer0/219ms7524 KiB
28Wrong answer0/216ms7620 KiB
29Wrong answer0/217ms7532 KiB
30Wrong answer0/217ms7532 KiB
31Wrong answer0/216ms7532 KiB
32Wrong answer0/217ms7588 KiB