結果
| 問題 |
No.30 たこやき工場
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-03-05 18:29:46 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,421 bytes |
| コンパイル時間 | 2,484 ms |
| コンパイル使用メモリ | 79,868 KB |
| 実行使用メモリ | 53,868 KB |
| 最終ジャッジ日時 | 2024-10-06 20:08:30 |
| 合計ジャッジ時間 | 11,575 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 TLE * 1 -- * 6 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
graph.add(new HashMap<>());
}
for (int i = 0; i < m; i++) {
int parts = sc.nextInt() - 1;
int count = sc.nextInt();
int product = sc.nextInt() - 1;
graph.get(product).put(parts, count);
}
ArrayDeque<Path> deq = new ArrayDeque<>();
deq.add(new Path(n - 1, 1));
long[] ans = new long[n];
while (deq.size() > 0) {
Path p = deq.poll();
if (graph.get(p.idx).size() == 0) {
ans[p.idx] += p.value;
} else {
for (int x : graph.get(p.idx).keySet()) {
deq.add(new Path(x, p.value * graph.get(p.idx).get(x)));
}
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n - 1; i++) {
sb.append(ans[i]).append("\n");
}
System.out.print(sb);
}
static class Path {
int idx;
long value;
public Path(int idx, long value) {
this.idx = idx;
this.value = value;
}
}
}
tenten