結果

問題 No.3018 簡易版ページランク
ユーザー 37zigen37zigen
提出日時 2016-09-12 18:32:00
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,444 bytes
コンパイル時間 4,638 ms
コンパイル使用メモリ 74,872 KB
実行使用メモリ 59,616 KB
最終ジャッジ日時 2023-09-17 19:32:31
合計ジャッジ時間 11,812 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
56,212 KB
testcase_01 AC 128 ms
57,828 KB
testcase_02 AC 132 ms
56,020 KB
testcase_03 AC 135 ms
55,716 KB
testcase_04 AC 139 ms
56,252 KB
testcase_05 AC 144 ms
55,780 KB
testcase_06 AC 146 ms
55,684 KB
testcase_07 AC 143 ms
55,720 KB
testcase_08 AC 145 ms
57,528 KB
testcase_09 AC 153 ms
56,120 KB
testcase_10 AC 186 ms
56,272 KB
testcase_11 AC 202 ms
56,684 KB
testcase_12 AC 189 ms
56,248 KB
testcase_13 AC 245 ms
58,788 KB
testcase_14 AC 241 ms
58,728 KB
testcase_15 AC 254 ms
59,068 KB
testcase_16 AC 249 ms
59,136 KB
testcase_17 AC 299 ms
59,616 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