結果
問題 | No.2726 Rooted Tree Nim |
ユーザー | koba-e964 |
提出日時 | 2024-04-13 12:03:21 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 229 ms / 2,000 ms |
コード長 | 2,038 bytes |
コンパイル時間 | 12,396 ms |
コンパイル使用メモリ | 378,444 KB |
実行使用メモリ | 39,552 KB |
最終ジャッジ日時 | 2024-10-03 00:01:55 |
合計ジャッジ時間 | 15,779 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 229 ms
5,248 KB |
testcase_02 | AC | 117 ms
8,576 KB |
testcase_03 | AC | 207 ms
39,552 KB |
testcase_04 | AC | 203 ms
39,424 KB |
testcase_05 | AC | 123 ms
22,144 KB |
testcase_06 | AC | 128 ms
22,144 KB |
testcase_07 | AC | 161 ms
23,040 KB |
testcase_08 | AC | 157 ms
22,912 KB |
testcase_09 | AC | 104 ms
7,040 KB |
testcase_10 | AC | 106 ms
7,124 KB |
testcase_11 | AC | 110 ms
9,088 KB |
testcase_12 | AC | 153 ms
20,528 KB |
testcase_13 | AC | 106 ms
6,920 KB |
コンパイルメッセージ
warning: unused variable: `sum` --> src/main.rs:66:17 | 66 | let mut sum = vec![0; n]; | ^^^ help: if this is intentional, prefix it with an underscore: `_sum` | = note: `#[warn(unused_variables)]` on by default warning: variable does not need to be mutable --> src/main.rs:66:13 | 66 | let mut sum = vec![0; n]; | ----^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::Read; fn get_word() -> String { let stdin = std::io::stdin(); let mut stdin=stdin.lock(); let mut u8b: [u8; 1] = [0]; loop { let mut buf: Vec<u8> = Vec::with_capacity(16); loop { let res = stdin.read(&mut u8b); if res.unwrap_or(0) == 0 || u8b[0] <= b' ' { break; } else { buf.push(u8b[0]); } } if buf.len() >= 1 { let ret = String::from_utf8(buf).unwrap(); return ret; } } } #[allow(dead_code)] fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); } fn dfs(v: usize, par: usize, root: usize, g: &Vec<Vec<usize>>, dep: &mut [usize], rs: &mut [usize]) { rs[v] = root; for &to in &g[v] { if to == par { continue; } dep[to] = dep[v] + 1; dfs(to, v, root, g, dep, rs); } } fn solve() { let t: i32 = get(); for _ in 0..t { let n: usize = get(); let k: i64 = get(); let mut g = vec![vec![]; n]; for _ in 0..n - 1 { let x = get::<usize>() - 1; let y = get::<usize>() - 1; g[x].push(y); g[y].push(x); } let a: Vec<i64> = (0..n).map(|_| get()).collect(); let mut dep = vec![0; n]; let mut rs = vec![0; n]; for &v in &g[0] { dep[v] = 1; dfs(v, 0, v, &g, &mut dep, &mut rs); } let mut sum = vec![0; n]; let mut g = 0; for i in 1..n { if dep[i] % 2 == 1 { g ^= a[i] % (k + 1); } } println!("{}", if g == 0 { "P" } else { "K" }) } }