47022023-03-31 09:43:05Erik_GepardHálózati átvitelcpp17Wrong answer 0/5017ms5816 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
int n, m, rajt, cel, h;
 
struct el{
  int a;
  int b;
  int suly;
};
 
el e1;
vector<el> e;
 
void bellman_ford(){
  vector<int> d(n+1, -1);
  d[rajt]=0;
  for(int i=0; i<h; i++){
    for(int j=0; j<2*m; j++){
      if(d[e[j].a]>-1){
        if(d[e[j].b]<e[j].suly){
          d[e[j].b]=e[j].suly;
        }
      }
    }
  }
  d[rajt]=0;
  for(int i=1; i<=n; i++){
    if(d[i]<1e9){
        cout<<d[i]<<"\n";
    }
    else{
        cout<<"-1\n";
    }
  }
}
 
 
void solve() {
  cin>>n>>m>>rajt>>h;
  for(int i=0; i<m; i++){
    int x, y, z;
    cin>>x>>y>>z;
    e1.a=x;
    e1.b=y;
    e1.suly=z;
    e.push_back(e1);
    e1.a=y;
    e1.b=x;
    e1.suly=z;
    e.push_back(e1);
  }
  bellman_ford();
}
 
int main() {
	ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/03ms1828 KiB
2Wrong answer0/03ms2212 KiB
3Wrong answer0/13ms2388 KiB
4Wrong answer0/13ms2492 KiB
5Wrong answer0/23ms2672 KiB
6Wrong answer0/23ms2772 KiB
7Wrong answer0/23ms3052 KiB
8Wrong answer0/23ms3136 KiB
9Wrong answer0/13ms3112 KiB
10Wrong answer0/13ms3176 KiB
11Wrong answer0/14ms3576 KiB
12Wrong answer0/14ms3988 KiB
13Wrong answer0/24ms3736 KiB
14Wrong answer0/24ms3940 KiB
15Wrong answer0/27ms4540 KiB
16Wrong answer0/27ms4648 KiB
17Wrong answer0/27ms4500 KiB
18Wrong answer0/27ms4388 KiB
19Wrong answer0/27ms4392 KiB
20Wrong answer0/27ms4392 KiB
21Wrong answer0/19ms4400 KiB
22Wrong answer0/110ms4680 KiB
23Wrong answer0/113ms4948 KiB
24Wrong answer0/114ms5516 KiB
25Wrong answer0/214ms5436 KiB
26Wrong answer0/216ms5680 KiB
27Wrong answer0/217ms5664 KiB
28Wrong answer0/214ms5728 KiB
29Wrong answer0/216ms5816 KiB
30Wrong answer0/216ms5732 KiB
31Wrong answer0/214ms5728 KiB
32Wrong answer0/217ms5728 KiB