結果
問題 | No.30 たこやき工場 |
ユーザー |
|
提出日時 | 2014-11-25 15:40:34 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,737 bytes |
コンパイル時間 | 3,723 ms |
コンパイル使用メモリ | 84,180 KB |
実行使用メモリ | 783,424 KB |
最終ジャッジ日時 | 2025-01-02 21:48:54 |
合計ジャッジ時間 | 16,207 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 TLE * 1 MLE * 1 |
ソースコード
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(); } } }