結果

問題 No.763 Noelちゃんと木遊び
ユーザー Kohei AsanoKohei Asano
提出日時 2021-02-04 17:54:24
言語 Rust
(1.77.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,773 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 153,096 KB
実行使用メモリ 18,316 KB
最終ジャッジ日時 2023-09-13 14:35:33
合計ジャッジ時間 2,806 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
18,316 KB
testcase_01 AC 19 ms
4,776 KB
testcase_02 AC 48 ms
8,720 KB
testcase_03 AC 29 ms
6,524 KB
testcase_04 AC 21 ms
5,320 KB
testcase_05 AC 28 ms
6,280 KB
testcase_06 AC 53 ms
10,180 KB
testcase_07 AC 53 ms
9,936 KB
testcase_08 AC 30 ms
6,784 KB
testcase_09 AC 20 ms
5,076 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 57 ms
10,424 KB
testcase_12 AC 51 ms
9,392 KB
testcase_13 AC 48 ms
9,196 KB
testcase_14 AC 42 ms
8,424 KB
testcase_15 AC 31 ms
6,480 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 29 ms
6,532 KB
testcase_18 AC 55 ms
10,096 KB
testcase_19 AC 53 ms
9,456 KB
testcase_20 AC 51 ms
9,436 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `leaf` is assigned to, but never used
 --> 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
  --> 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
 --> Main.rs:1:4
  |
1 | fn solve() {
  |    ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 3 warnings emitted

ソースコード

diff #

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")
}

// =========
0