結果

問題 No.30 たこやき工場
ユーザー scachescache
提出日時 2014-11-25 16:38:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 221 ms / 5,000 ms
コード長 1,153 bytes
コンパイル時間 4,688 ms
コンパイル使用メモリ 74,288 KB
実行使用メモリ 59,168 KB
最終ジャッジ日時 2023-08-23 05:14:10
合計ジャッジ時間 8,108 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,680 KB
testcase_01 AC 128 ms
55,868 KB
testcase_02 AC 131 ms
55,660 KB
testcase_03 AC 135 ms
55,968 KB
testcase_04 AC 134 ms
55,792 KB
testcase_05 AC 135 ms
55,784 KB
testcase_06 AC 136 ms
55,724 KB
testcase_07 AC 135 ms
55,516 KB
testcase_08 AC 187 ms
55,704 KB
testcase_09 AC 199 ms
56,216 KB
testcase_10 AC 221 ms
59,168 KB
testcase_11 AC 165 ms
55,908 KB
testcase_12 AC 136 ms
55,680 KB
testcase_13 AC 148 ms
55,784 KB
testcase_14 AC 190 ms
56,124 KB
testcase_15 AC 195 ms
56,320 KB
testcase_16 AC 198 ms
56,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main30 {


	public static void main(String[] args) {
		Main30 p = new Main30();
	}

	boolean[] isVisited;
	long[][] need;
	
	public Main30() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		isVisited = new boolean[n+1];
		need = new long[n+1][n+1];
		
		for(int i=0;i<m;i++){
			int p = sc.nextInt();
			int q = sc.nextInt();
			int r = sc.nextInt();
			
			need[r][p] = q;
		}
		
		solve(need);
		
	}

	public void solve(long[][] need){
		int n = need.length-1;
		rec(n);
		for(int i=1;i<n;i++)
			System.out.println(need[n][i]);

	}	
	
	private void rec(int cur) {
		if(isVisited[cur])
			return;
		
		boolean isTerm = true;
		for(int i=1;i<need[cur].length;i++){
			if(need[cur][i]==0)
				continue;
			
			isTerm = false;
			rec(i);
			long curr = need[cur][i];
			need[cur][i] = 0;
			for(int j=1;j<need[i].length;j++){
				need[cur][j] += curr*need[i][j];
			}
		}
		
		if(isTerm)
			need[cur][cur] = 1;
		
		isVisited[cur] = true;		
	}

}
0