結果

問題 No.2726 Rooted Tree Nim
ユーザー 37kt37kt
提出日時 2024-05-08 08:47:02
言語 Rust
(1.77.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 13,579 ms
コンパイル使用メモリ 388,936 KB
実行使用メモリ 25,984 KB
最終ジャッジ日時 2024-05-08 08:47:24
合計ジャッジ時間 16,694 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 174 ms
5,504 KB
testcase_02 AC 69 ms
12,160 KB
testcase_03 AC 134 ms
23,552 KB
testcase_04 AC 131 ms
23,536 KB
testcase_05 AC 75 ms
25,856 KB
testcase_06 AC 73 ms
25,984 KB
testcase_07 AC 91 ms
25,788 KB
testcase_08 AC 87 ms
25,836 KB
testcase_09 AC 58 ms
10,752 KB
testcase_10 AC 60 ms
10,668 KB
testcase_11 AC 62 ms
12,544 KB
testcase_12 AC 94 ms
23,424 KB
testcase_13 AC 60 ms
10,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use proconio::{
    input,
    marker::{Bytes, Chars, Usize1},
};

fn main() {
    input! {
        t: usize,
    }
    for _ in 0..t {
        input! {
            n: usize,
            m: usize,
        }
        let mut g = vec![vec![]; n];
        for _ in 0..n - 1 {
            input! {
                a: Usize1,
                b: Usize1,
            }
            g[a].push(b);
            g[b].push(a);
        }
        input! {
            a: [usize; n],
        }
        let mut d = vec![!0; n];
        let mut st = vec![0];
        d[0] = 0;
        while let Some(v) = st.pop() {
            for &u in &g[v] {
                if d[u] == !0 {
                    d[u] = d[v] + 1;
                    st.push(u);
                }
            }
        }
        let mut s = 0;
        for i in 0..n {
            s ^= (d[i] & 1) * (a[i] % (m + 1));
        }
        println!("{}", if s == 0 { "P" } else { "K" });
    }
}
0