結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー | Kohei Asano |
提出日時 | 2021-02-04 17:54:24 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,773 bytes |
コンパイル時間 | 12,329 ms |
コンパイル使用メモリ | 402,260 KB |
実行使用メモリ | 18,304 KB |
最終ジャッジ日時 | 2024-06-30 23:17:04 |
合計ジャッジ時間 | 14,284 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
18,304 KB |
testcase_01 | AC | 14 ms
6,816 KB |
testcase_02 | AC | 37 ms
8,704 KB |
testcase_03 | AC | 24 ms
6,940 KB |
testcase_04 | AC | 16 ms
6,944 KB |
testcase_05 | AC | 23 ms
6,940 KB |
testcase_06 | AC | 45 ms
10,112 KB |
testcase_07 | AC | 51 ms
9,856 KB |
testcase_08 | AC | 27 ms
6,944 KB |
testcase_09 | AC | 16 ms
6,940 KB |
testcase_10 | AC | 6 ms
6,940 KB |
testcase_11 | AC | 49 ms
10,240 KB |
testcase_12 | AC | 45 ms
9,344 KB |
testcase_13 | AC | 47 ms
9,216 KB |
testcase_14 | AC | 41 ms
8,448 KB |
testcase_15 | AC | 23 ms
6,940 KB |
testcase_16 | AC | 4 ms
6,940 KB |
testcase_17 | AC | 24 ms
6,944 KB |
testcase_18 | AC | 48 ms
10,240 KB |
testcase_19 | AC | 46 ms
9,472 KB |
testcase_20 | AC | 46 ms
9,472 KB |
コンパイルメッセージ
warning: variable `leaf` is assigned to, but never used --> src/main.rs:9:13 | 9 | let mut leaf = true; | ^^^^ | = note: consider using `_leaf` instead = note: `#[warn(unused_variables)]` on by default warning: value assigned to `leaf` is never read --> src/main.rs:15:9 | 15 | leaf = false; | ^^^^ | = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` on by default warning: function `solve` is never used --> src/main.rs:1:4 | 1 | fn solve() { | ^^^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
fn solve() { let (a, b, c): (usize, usize, usize) = (read(), read(), read()); println!("{:?}", a + b + c); let s: String = read(); println!("{:?}", s); } fn dfs(u: usize, p: usize, adjl: &Vec<Vec<usize>>, dp: &mut Vec<Vec<usize>>) { let mut leaf = true; // 残した時に消える個数 for &v in &adjl[u] { if v == p { continue; } leaf = false; dfs(v, u, adjl, dp); // 残した方が良い子を数える. dp[0][u] += max(dp[0][v] - 1, dp[1][v]); dp[1][u] += max(dp[0][v], dp[1][v]); } } fn main() { let n = read(); let mut adjl: Vec<Vec<usize>> = vec![vec![]; n]; for _ in 0..n - 1 { let (mut x, mut y): (usize, usize) = (read::<usize>(), read::<usize>()); x -= 1; y -= 1; adjl[x].push(y); adjl[y].push(x); } // dp[0][i] ... i番目を消す // dp[1][u] ... 1番目を残す let mut dp = vec![vec![0; n]; 2]; for i in 0..n { dp[0][i] = 1; } dfs(0, 0, &adjl, &mut dp); println!("{}", max(dp[0][0], dp[1][0])); } // ========= #[allow(unused_imports)] use std::cmp::{max, min, Reverse}; #[allow(unused_imports)] use std::collections::{BinaryHeap, HashMap, HashSet}; #[allow(unused_imports)] use std::process::exit; #[allow(dead_code)] const MOD: usize = 1000000007; fn read<T: std::str::FromStr>() -> T { use std::io::Read; let stdin = std::io::stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") } // =========