結果

問題 No.30 たこやき工場
ユーザー tonyu0tonyu0
提出日時 2019-12-24 13:16:37
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 999 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 173,548 KB
実行使用メモリ 6,352 KB
最終ジャッジ日時 2023-10-21 19:51:40
合計ジャッジ時間 7,550 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn dfs(v: usize, cost: u32, graph: &Vec<Vec<(usize, u32)>>, ans: &mut Vec<u32>) {
    if graph[v].len() == 0 {
        ans[v] += cost;
        return;
    }
    for &(nv, nc) in graph[v].iter() {
        dfs(nv, cost * nc, graph, ans);
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();

    let mut graph: Vec<Vec<(usize, u32)>> = vec![Vec::new(); n];

    for _ in 0..m {
        let p: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let q: u32 = itr.next().unwrap().parse().unwrap();
        let r: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        graph[r].push((p, q));
    }
    let mut ans: Vec<u32> = vec![0; n];
    dfs(n - 1, 1, &graph, &mut ans);
    for i in 0..n - 1 {
        println!("{}", ans[i]);
    }
}
0