結果

問題 No.3018 簡易版ページランク
ユーザー uafr_csuafr_cs
提出日時 2017-11-07 21:24:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 833 ms / 2,000 ms
コード長 1,598 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 75,200 KB
実行使用メモリ 65,264 KB
最終ジャッジ日時 2023-08-15 20:18:14
合計ジャッジ時間 10,765 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
55,924 KB
testcase_01 AC 141 ms
56,072 KB
testcase_02 AC 153 ms
56,004 KB
testcase_03 AC 161 ms
55,680 KB
testcase_04 AC 160 ms
56,052 KB
testcase_05 AC 166 ms
56,096 KB
testcase_06 AC 171 ms
56,272 KB
testcase_07 AC 187 ms
56,432 KB
testcase_08 AC 188 ms
56,152 KB
testcase_09 AC 220 ms
56,728 KB
testcase_10 AC 243 ms
59,068 KB
testcase_11 AC 242 ms
58,640 KB
testcase_12 AC 234 ms
58,760 KB
testcase_13 AC 276 ms
60,020 KB
testcase_14 AC 319 ms
61,504 KB
testcase_15 AC 296 ms
59,656 KB
testcase_16 AC 329 ms
61,844 KB
testcase_17 AC 355 ms
62,452 KB
testcase_18 AC 469 ms
63,896 KB
testcase_19 AC 522 ms
62,824 KB
testcase_20 AC 621 ms
65,264 KB
testcase_21 AC 663 ms
63,868 KB
testcase_22 AC 833 ms
64,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Map.Entry;

public class Main {
	
	public static long MOD = 1000000007;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		
		ArrayList<HashMap<Integer, Double>> adj = new ArrayList<HashMap<Integer, Double>>();
		for(int i = 0; i < N; i++){ adj.add(new HashMap<Integer, Double>()); }
		
		for(int i = 0; i < M; i++){
			final int a = sc.nextInt();
			final int b = sc.nextInt();
			final double c = sc.nextDouble();
			
			if(!adj.get(a).containsKey(b)){
				adj.get(a).put(b, c);
			}else{
				adj.get(a).put(b, c);
			}
		}
		
		double[] out_sum = new double[N];
		for(int curr = 0; curr < N; curr++){
			for(final double denom : adj.get(curr).values()){
				out_sum[curr] += denom;
			}
		}
		
		double[] curr_rank = new double[N];
		for(int i = 0; i < N; i++){ curr_rank[i] = 10; }
		double[] next_rank = new double[N];
		
		for(int i = 0; i < 100; i++){
			Arrays.fill(next_rank, 0);
			
			for(int curr = 0; curr < N; curr++){
				for(final Entry<Integer, Double> entry : adj.get(curr).entrySet()){
					final int next = entry.getKey();
					final double mul = entry.getValue();
					
					next_rank[next] += curr_rank[curr] * mul / out_sum[curr];
				}
			}
			
			{
				double[] tmp = curr_rank;
				curr_rank = next_rank;
				next_rank = tmp;
			}
		}
		
		for(int i = 0; i < N; i++){
			System.out.printf("%.08f\n", curr_rank[i]);
		}

	}
}
0