96342024-02-23 15:51:35PallanekPéterHálózati átvitelcpp14Accepted 50/5046ms13336 KiB
#include <bits/stdc++.h>
using namespace std;
vector<array<int, 3>> g;
bool seen[100001];

int main() {
	int n,m,k,h;
	cin >> n >> m >> k >> h;
	for (int i=0;i<m;i++){
		int u,v,b;
		cin >> u >> v >> b;
		g.push_back({u,v,b});
	}
	vector<vector<int>> dp(n+1,vector<int>(h+1,0));
	dp[k][0]=1e9;
	for (int j=1;j<=h;j++){
		for (int i=1;i<=n;i++) dp[i][j]=dp[i][j-1];
        for (array<int, 3> edge:g){
            dp[edge[0]][j]=max(dp[edge[0]][j],min(dp[edge[1]][j-1],edge[2]));
            dp[edge[1]][j]=max(dp[edge[1]][j],min(dp[edge[0]][j-1],edge[2]));
		}
	}
	for (int i=1;i<=n;i++){
		if (i==k) cout<< 0 <<"\n";
		else{
		 if (dp[i][h]==0) cout<< -1 << "\n";
		 else cout << dp[i][h] << "\n";
		}
	}
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1820 KiB
2Accepted0/03ms2064 KiB
3Accepted1/13ms2248 KiB
4Accepted1/13ms2468 KiB
5Accepted2/23ms2684 KiB
6Accepted2/23ms2900 KiB
7Accepted2/23ms3140 KiB
8Accepted2/23ms3104 KiB
9Accepted1/14ms3356 KiB
10Accepted1/14ms3488 KiB
11Accepted1/18ms3540 KiB
12Accepted1/17ms3768 KiB
13Accepted2/26ms4004 KiB
14Accepted2/28ms4216 KiB
15Accepted2/213ms4372 KiB
16Accepted2/212ms4336 KiB
17Accepted2/213ms4628 KiB
18Accepted2/214ms4848 KiB
19Accepted2/213ms4656 KiB
20Accepted2/213ms4904 KiB
21Accepted1/124ms11956 KiB
22Accepted1/128ms11600 KiB
23Accepted1/132ms11528 KiB
24Accepted1/137ms11916 KiB
25Accepted2/243ms13332 KiB
26Accepted2/243ms13256 KiB
27Accepted2/246ms13336 KiB
28Accepted2/241ms12136 KiB
29Accepted2/245ms13292 KiB
30Accepted2/243ms13288 KiB
31Accepted2/243ms13320 KiB
32Accepted2/246ms13316 KiB