Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
2
Indexable
Never
#include <iostream>
#include <stdio.h>
using namespace std;

int n, e, k, t;
float w[101][101];
float arr[101][101];

void sub() {

	arr[0][1] = 1;
	
	for (int i = 0; i <= t / 10; i++) {

		for (int j = 1; j <= n; j++) {
			float temp = arr[i][j];

			if (temp != 0) {
				for (int k = 1; k <= n; k++) {
					if (w[j][k] != 0) {

						arr[i + 1][k] += (temp * w[j][k]);

					}
				}
			}
		}

	}

}


int main() {

	for (int tc = 1; tc <= 10; tc++) {

		cin >> n >> e >> k >> t;

		for (int i = 0; i < 101; i++) {
			for (int j = 0; j < 101; j++) {
				w[i][j] = 0;
				arr[i][j] = 0;
			}
		}

		int x, y;
		float p;

		for (int i = 0; i < e; i++) {
			cin >> x >> y >> p;
			w[x][y] = p;
		}

		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				cout << w[i][j] << " ";
			}
			cout << endl;
		}

		sub();

		/*cout << endl;

		for (int i = 0; i <= t / 10; i++) {
			for (int j = 1; j <= n; j++) {
				cout << arr[i][j] << " ";
			}
			cout << endl;
		}*/

		float maxXS1 = 0;
		int room1 = 0;

		for (int i = 1; i <= n; i++) {
			if (arr[t / 10][i] > maxXS1) {
				maxXS1 = arr[t / 10][i];
				room1 = i;
			}
		}

		float maxXS2 = 0;
		int room2 = 0;

		for (int i = 1; i <= n; i++) {
			if (arr[(t - k) / 10][i] > maxXS2) {
				maxXS2 = arr[(t - k) / 10][i];
				room2 = i;
			}
		}

		cout << "#" << tc << " ";

		printf("%d %.6f %d %.6f\n", room1, maxXS1, room2, maxXS2);
	}
}