結果

問題 No.30 たこやき工場
コンテスト
ユーザー Daigo HIROOKA
提出日時 2018-07-01 03:31:54
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 896 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,395 ms
コンパイル使用メモリ 82,708 KB
実行使用メモリ 47,776 KB
最終ジャッジ日時 2026-05-27 22:28:53
合計ジャッジ時間 4,609 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

public class No030{
	static int[] dp;
	static int[][] in;
	
	static int dfs(int i, int n){
		if(i == n) return 1;
		if(dp[i] != 0) return dp[i];
		int res = 0;
		for(int j = 1; j < 101; j++){
			if(in[i][j] != 0){
				res += in[i][j]*dfs(j, n);
			}
		}
		return dp[i] = res;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		dp = new int[101];
		int[] ans = new int[101];
		Arrays.fill(ans, -1);
		in = new int[101][101];
		for(int i = 0; i < m; i++){
			int p = sc.nextInt();
			int q = sc.nextInt();
			int r = sc.nextInt();
			in[p][r] = q;
		}

		for(int i = 1; i < n; i++){
			boolean flg = true;
			for(int j = 1; j < 101; j++){
				if(in[j][i] != 0){
					System.out.println(0);
					flg = false;
					break;
				}
			}
			if(flg){
				System.out.println(dfs(i, n));
			}
		}
	}
}
0