結果
問題 | No.30 たこやき工場 |
ユーザー |
|
提出日時 | 2014-11-25 16:38:16 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 236 ms / 5,000 ms |
コード長 | 1,153 bytes |
コンパイル時間 | 4,457 ms |
コンパイル使用メモリ | 77,416 KB |
実行使用メモリ | 57,456 KB |
最終ジャッジ日時 | 2024-12-21 05:18:24 |
合計ジャッジ時間 | 7,542 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
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; } }