結果

問題 No.30 たこやき工場
ユーザー uafr_csuafr_cs
提出日時 2017-11-01 22:51:01
言語 Java19
(openjdk 21)
結果
AC  
実行時間 236 ms / 5,000 ms
コード長 1,536 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 81,048 KB
実行使用メモリ 60,816 KB
最終ジャッジ日時 2023-08-23 05:19:42
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,560 KB
testcase_01 AC 132 ms
55,716 KB
testcase_02 AC 133 ms
55,708 KB
testcase_03 AC 134 ms
55,788 KB
testcase_04 AC 135 ms
55,804 KB
testcase_05 AC 134 ms
55,376 KB
testcase_06 AC 145 ms
55,712 KB
testcase_07 AC 138 ms
55,560 KB
testcase_08 AC 193 ms
56,108 KB
testcase_09 AC 204 ms
56,944 KB
testcase_10 AC 236 ms
60,816 KB
testcase_11 AC 187 ms
55,948 KB
testcase_12 AC 136 ms
55,784 KB
testcase_13 AC 151 ms
55,780 KB
testcase_14 AC 192 ms
56,228 KB
testcase_15 AC 197 ms
56,792 KB
testcase_16 AC 206 ms
57,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		
		int[] in_degs = new int[N];
		ArrayList<HashMap<Integer, Long>> rev_adj = new ArrayList<HashMap<Integer, Long>>();
		for(int i = 0; i < N; i++){ rev_adj.add(new HashMap<Integer, Long>()); }
		
		for(int i = 0; i < M; i++){
			final int P = sc.nextInt() - 1;
			final long Q = sc.nextLong();
			final int R = sc.nextInt() - 1;
			
			in_degs[R]++;
			if(!rev_adj.get(P).containsKey(R)){
				rev_adj.get(P).put(R, Q);
			}else{
				rev_adj.get(P).put(R, Math.min(Q, rev_adj.get(P).get(R)));
			}
		}
		
		LinkedList<Integer> queue = new LinkedList<Integer>();
		long[][] comps = new long[N][N];
		for(int i = 0; i < N; i++){
			if(in_degs[i] != 0){ continue; }
			comps[i][i] = 1;
			queue.add(i);
		}
		
		while(!queue.isEmpty()){
			final int node = queue.poll();
			
			for(final Entry<Integer, Long> entry : rev_adj.get(node).entrySet()){
				final int from = entry.getKey();
				final long value = entry.getValue();
				
				for(int i = 0; i < N; i++){
					comps[from][i] += value * comps[node][i];
				}
				
				in_degs[from]--;
				if(in_degs[from] == 0){ queue.add(from); }
			}
		}
		
		for(int i = 0; i < N - 1; i++){
			System.out.println(comps[N - 1][i]);
		}
	}
}
0