43392023-03-25 15:49:52szilHálózati átvitelcpp14Accepted 50/5024ms12444 KiB
#include <bits/stdc++.h>
 
using ll = long long;
using namespace std;

const int MAXN = 10001;

struct Edge {
	int a, b, w;
};

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m, k, h;
	cin >> n >> m >> k >> h;

	vector<Edge> edges;
	for (int i = 0; i < m; i++) {
		Edge e;
		cin >> e.a >> e.b >> e.w;
		edges.push_back(e);
	}

	vector<vector<int>> d(h+1, vector<int>(MAXN, INT_MIN));
	d[0][k] = INT_MAX;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= n; j++) d[i][j] = d[i-1][j];
		for (Edge e : edges) {
			if (d[i][e.a] != INT_MIN)
				d[i][e.b] = max(d[i][e.b], min(d[i-1][e.a],e.w));
			if (d[i][e.b] != INT_MIN)
				d[i][e.a] = max(d[i][e.a], min(d[i-1][e.b],e.w));
		}
	}

	for (int i = 1; i <= n; i++) {
		if (d[h][i] < -1000000) {
			cout << "-1\n";
		} else {
			cout << (i==k?0:d[h][i]) << "\n";
		}
	}
	cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2248 KiB
2Accepted0/03ms2712 KiB
3Accepted1/13ms2604 KiB
4Accepted1/13ms3456 KiB
5Accepted2/23ms3288 KiB
6Accepted2/23ms3688 KiB
7Accepted2/23ms3516 KiB
8Accepted2/23ms3580 KiB
9Accepted1/14ms4356 KiB
10Accepted1/14ms5044 KiB
11Accepted1/14ms5480 KiB
12Accepted1/14ms4960 KiB
13Accepted2/24ms5836 KiB
14Accepted2/24ms5552 KiB
15Accepted2/28ms7212 KiB
16Accepted2/27ms5736 KiB
17Accepted2/28ms6776 KiB
18Accepted2/29ms8500 KiB
19Accepted2/28ms7468 KiB
20Accepted2/28ms6936 KiB
21Accepted1/114ms10820 KiB
22Accepted1/114ms10396 KiB
23Accepted1/117ms10348 KiB
24Accepted1/118ms10624 KiB
25Accepted2/221ms12440 KiB
26Accepted2/221ms12400 KiB
27Accepted2/224ms12332 KiB
28Accepted2/219ms11300 KiB
29Accepted2/221ms12444 KiB
30Accepted2/220ms12328 KiB
31Accepted2/221ms12332 KiB
32Accepted2/221ms12372 KiB