結果

問題 No.30 たこやき工場
ユーザー scachescache
提出日時 2014-11-25 15:40:34
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,737 bytes
コンパイル時間 3,535 ms
コンパイル使用メモリ 74,856 KB
実行使用メモリ 63,716 KB
最終ジャッジ日時 2023-08-30 22:58:34
合計ジャッジ時間 13,979 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,184 KB
testcase_01 AC 124 ms
56,200 KB
testcase_02 AC 126 ms
55,832 KB
testcase_03 AC 130 ms
56,112 KB
testcase_04 AC 128 ms
56,148 KB
testcase_05 AC 127 ms
56,028 KB
testcase_06 AC 136 ms
56,224 KB
testcase_07 AC 131 ms
55,692 KB
testcase_08 AC 265 ms
63,716 KB
testcase_09 AC 188 ms
56,280 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

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();
	}

	public Main30() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Product[] products = new Product[n+1];
		for(int i=0;i<products.length;i++)
			products[i] = new Product(i);
		
		for(int i=0;i<m;i++){
			int p = sc.nextInt();
			int q = sc.nextInt();
			int r = sc.nextInt();
			
			products[r].add(p, q);
		}
		
		solve(products);
	}

	public void solve(Product[] products) {
		long[] need = new long[products.length];
		need[products.length-1] = 1;
		LinkedList<Integer> queue = new LinkedList<Integer>();
		queue.add(products.length-1);
		
		while(!queue.isEmpty()){
			int index = queue.poll();
			if(products[index].size()==0)
				continue;
			
			for(int i=0;i<products[index].size();i++){
				int p = products[index].getP(i);
				int r = products[index].getR(i);
				
				need[p] += need[index]*r;
				queue.add(p);
			}
			need[index] = 0;
		}
		
		for(int i=1;i<need.length-1;i++)
			System.out.println(need[i]);
		
		
	}
	


	public class Product {
		public int number;
		public ArrayList<Integer> pl;
		public ArrayList<Integer> rl;
		
		public Product(int number) {
			this.number = number;
			this.pl = new ArrayList<Integer>();
			this.rl = new ArrayList<Integer>();
		}
			
		
		public void add(int q, int r){
			pl.add(q);
			rl.add(r);
		}
		
		public int getP(int i){
			return pl.get(i);
		}
		
		public int getR(int i){
			return rl.get(i);
		}
		
		public int size(){
			return pl.size();
		}
	}
	
}
0