43382023-03-25 15:45:54szilHálózati átvitelcpp14Wrong answer 0/5037ms62856 KiB
#include <bits/stdc++.h>
 
using ll = long long;
using namespace std;

const int MAXN = 100001;

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));
	for (int i = 0; i <= h; i++) d[i][k] = INT_MAX;
	for (int i = 1; i <= h; i++) {
		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
base0/50
1Accepted0/04ms4856 KiB
2Wrong answer0/06ms9840 KiB
3Wrong answer0/14ms7788 KiB
4Wrong answer0/16ms10048 KiB
5Wrong answer0/27ms12136 KiB
6Wrong answer0/26ms13792 KiB
7Wrong answer0/26ms10496 KiB
8Wrong answer0/26ms10560 KiB
9Wrong answer0/18ms16280 KiB
10Wrong answer0/112ms24476 KiB
11Wrong answer0/114ms28328 KiB
12Wrong answer0/112ms20100 KiB
13Wrong answer0/214ms28544 KiB
14Wrong answer0/213ms25676 KiB
15Wrong answer0/223ms40676 KiB
16Wrong answer0/216ms25212 KiB
17Wrong answer0/219ms33268 KiB
18Wrong answer0/228ms52840 KiB
19Wrong answer0/223ms41140 KiB
20Wrong answer0/218ms33592 KiB
21Runtime error0/134ms62856 KiB
22Runtime error0/129ms62616 KiB
23Runtime error0/135ms62592 KiB
24Runtime error0/132ms62564 KiB
25Runtime error0/232ms62552 KiB
26Runtime error0/237ms62520 KiB
27Runtime error0/232ms62512 KiB
28Runtime error0/235ms62464 KiB
29Runtime error0/232ms62468 KiB
30Runtime error0/232ms62272 KiB
31Runtime error0/230ms62288 KiB
32Runtime error0/232ms62052 KiB