結果

問題 No.3018 簡易版ページランク
ユーザー 37zigen37zigen
提出日時 2016-09-12 18:32:03
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,444 bytes
コンパイル時間 3,455 ms
コンパイル使用メモリ 78,988 KB
実行使用メモリ 75,536 KB
最終ジャッジ日時 2023-09-17 19:32:42
合計ジャッジ時間 10,463 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,688 KB
testcase_01 AC 126 ms
55,820 KB
testcase_02 AC 130 ms
55,940 KB
testcase_03 AC 132 ms
55,964 KB
testcase_04 AC 134 ms
55,816 KB
testcase_05 AC 140 ms
55,960 KB
testcase_06 AC 140 ms
55,604 KB
testcase_07 AC 145 ms
55,864 KB
testcase_08 AC 143 ms
55,664 KB
testcase_09 AC 147 ms
55,624 KB
testcase_10 AC 184 ms
56,192 KB
testcase_11 AC 202 ms
57,168 KB
testcase_12 AC 191 ms
55,940 KB
testcase_13 AC 243 ms
58,688 KB
testcase_14 AC 253 ms
59,108 KB
testcase_15 AC 246 ms
58,900 KB
testcase_16 AC 257 ms
57,156 KB
testcase_17 AC 302 ms
59,772 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class Q1191 {
	public static void main(String[] args) {
		new Q1191().solver();
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		double[][] matrix = new double[n][n];

		for (int i = 0; i < m; i++) {
			int src = sc.nextInt();
			int dst = sc.nextInt();
			int rate = sc.nextInt();
			matrix[dst][src] = rate;
		}

		for (int i = 0; i < n; i++) {
			double sum = 0;
			for (int j = 0; j < n; j++) {
				sum += matrix[j][i];
			}
			for (int j = 0; j < n; j++) {
				matrix[j][i] /= sum;
			}
		}

		double[][] state = new double[n][1];
		for (int i = 0; i < n; i++) {
			state[i][0] = 10;
		}

		state = MtPow(100, matrix, state);
		for (int i = 0; i < n; i++) {
			System.out.println(state[i][0]);
		}

	}

	class Edge {
		int src;
		int dst;
		int rate;

		public Edge(int src, int dst, int rate) {
			this.src = src;
			this.dst = dst;
			this.rate = rate;
		}
	}

	double[][] MtPow(long n, double[][] A, double[][] v) {
		for (; n > 0; n = n >> 1) {
			if ((n & 1) == 1)
				v = MtPrd(A, v);
			A = MtPrd(A, A);
		}
		return v;
	}

	double[][] MtPrd(double[][] A, double[][] B) {
		double[][] C = new double[A.length][B[0].length];
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < B[0].length; j++) {
				for (int k = 0; k < A[0].length; k++) {
					C[i][j] += A[i][k] * B[k][j];
				}
			}
		}
		return C;
	}
}
0