44052023-03-27 17:21:43horvathabelHálózati átvitelcpp17Accepted 50/5063ms13460 KiB
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>,int>> g;
bool seen[100001];

int main() {
	int n,m,k,h;
	cin>>n>>m>>k>>h;
	for (int i=0; i<m;i++){
		int x,y,c;
		cin>>x>>y>>c; 
		g.push_back({{x,y},c});
	}
	vector<vector<int>> dp;
	dp.resize(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 (pair<pair<int,int>, int> edge:g){
				dp[edge.first.first][j]=max(dp[edge.first.first][j],min(dp[edge.first.second][j-1],edge.second));
				dp[edge.first.second][j]=max(dp[edge.first.second][j],min(dp[edge.first.first][j-1],edge.second));
		}
	}
	for (int i=1; i<=n;i++){
		if (i==k) cout<<0<<endl; 
		else{
		 if (dp[i][h]==0) cout<<-1<<endl;
		 else cout<<dp[i][h]<<endl;
		}
	} 
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1820 KiB
2Accepted0/03ms2024 KiB
3Accepted1/13ms2360 KiB
4Accepted1/13ms2384 KiB
5Accepted2/23ms2596 KiB
6Accepted2/23ms2680 KiB
7Accepted2/24ms2952 KiB
8Accepted2/23ms2908 KiB
9Accepted1/14ms3404 KiB
10Accepted1/14ms3484 KiB
11Accepted1/17ms3784 KiB
12Accepted1/18ms4032 KiB
13Accepted2/28ms4060 KiB
14Accepted2/29ms4212 KiB
15Accepted2/214ms4420 KiB
16Accepted2/214ms4328 KiB
17Accepted2/214ms4648 KiB
18Accepted2/216ms4748 KiB
19Accepted2/214ms4704 KiB
20Accepted2/214ms4772 KiB
21Accepted1/141ms11764 KiB
22Accepted1/148ms11824 KiB
23Accepted1/143ms11424 KiB
24Accepted1/146ms11772 KiB
25Accepted2/252ms13348 KiB
26Accepted2/259ms13308 KiB
27Accepted2/263ms13336 KiB
28Accepted2/261ms12288 KiB
29Accepted2/256ms13324 KiB
30Accepted2/254ms13340 KiB
31Accepted2/254ms13308 KiB
32Accepted2/256ms13460 KiB