結果
問題 | No.1295 木と駒 |
ユーザー | akakimidori |
提出日時 | 2020-11-20 22:23:37 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,932 bytes |
コンパイル時間 | 14,748 ms |
コンパイル使用メモリ | 379,156 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-23 13:19:28 |
合計ジャッジ時間 | 15,761 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | WA | - |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | WA | - |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | WA | - |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
コンパイルメッセージ
warning: unused import: `std::io::Write` --> src/main.rs:51:5 | 51 | use std::io::Write; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused variable: `out` --> src/main.rs:103:13 | 103 | let mut out = std::io::BufWriter::new(out.lock()); | ^^^ help: if this is intentional, prefix it with an underscore: `_out` | = note: `#[warn(unused_variables)]` on by default warning: variable does not need to be mutable --> src/main.rs:103:9 | 103 | let mut out = std::io::BufWriter::new(out.lock()); | ----^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
ソースコード
// ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- use std::io::Write; fn run() { input! { n: usize, e: [(usize1, usize1); n - 1], } assert!(n < 5000); let mut g = vec![vec![]; n]; for &(a, b) in e.iter() { g[a].push(b); g[b].push(a); } g.iter_mut().for_each(|g| g.sort()); for root in 0..n { let mut topo = vec![root]; let mut parent = vec![n; n]; for i in 0..n { let v = topo[i]; for &u in g[v].iter() { if u != parent[v] { parent[u] = v; topo.push(u); } } } let mut dp = vec![(true, true, n); n]; for &v in topo.iter().rev() { let mut child = vec![]; for &u in g[v].iter() { if u != parent[v] { child.push(dp[u]); } } if child.is_empty() { continue; } dp[v].0 = child.iter().all(|p| p.0 && p.2 > v); let len = child.len(); for p in child.iter().take(len - 1) { dp[v].1 &= p.0 && p.2 > v; } dp[v].1 &= child[len - 1].1; dp[v].2 = *g[v].iter().filter(|p| **p != parent[v]).min().unwrap(); } if dp[root].1 { println!("Yes"); } else { println!("No"); } } let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); } fn main() { run(); }