結果

問題 No.2822 Lights Up! (Tree Edition)
ユーザー 37kt37kt
提出日時 2024-08-08 14:44:56
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 5,823 bytes
コンパイル時間 14,377 ms
コンパイル使用メモリ 376,592 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-08-08 14:45:18
合計ジャッジ時間 19,628 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 17 ms
8,064 KB
testcase_03 AC 17 ms
8,064 KB
testcase_04 AC 17 ms
8,064 KB
testcase_05 AC 15 ms
8,064 KB
testcase_06 AC 15 ms
8,064 KB
testcase_07 AC 15 ms
8,064 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 13 ms
7,552 KB
testcase_10 AC 12 ms
6,528 KB
testcase_11 AC 9 ms
5,376 KB
testcase_12 AC 11 ms
5,888 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 12 ms
6,016 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 3 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 1 ms
5,376 KB
testcase_53 AC 1 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 1 ms
5,376 KB
testcase_57 AC 1 ms
5,376 KB
testcase_58 AC 1 ms
5,376 KB
testcase_59 AC 1 ms
5,376 KB
testcase_60 AC 1 ms
5,376 KB
testcase_61 AC 1 ms
5,376 KB
testcase_62 AC 1 ms
5,376 KB
testcase_63 AC 1 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
testcase_65 AC 1 ms
5,376 KB
testcase_66 AC 1 ms
5,376 KB
testcase_67 AC 1 ms
5,376 KB
testcase_68 AC 1 ms
5,376 KB
testcase_69 AC 1 ms
5,376 KB
testcase_70 AC 1 ms
5,376 KB
testcase_71 AC 1 ms
5,376 KB
testcase_72 AC 1 ms
5,376 KB
testcase_73 AC 1 ms
5,376 KB
testcase_74 AC 1 ms
5,376 KB
testcase_75 AC 1 ms
5,376 KB
testcase_76 AC 1 ms
5,376 KB
testcase_77 AC 1 ms
5,376 KB
testcase_78 AC 1 ms
5,376 KB
testcase_79 AC 1 ms
5,376 KB
testcase_80 AC 1 ms
5,376 KB
testcase_81 AC 1 ms
5,376 KB
testcase_82 AC 1 ms
5,376 KB
testcase_83 AC 1 ms
5,376 KB
testcase_84 AC 1 ms
5,376 KB
testcase_85 AC 1 ms
5,376 KB
testcase_86 AC 0 ms
5,376 KB
testcase_87 AC 1 ms
5,376 KB
testcase_88 AC 1 ms
5,376 KB
testcase_89 AC 1 ms
5,376 KB
testcase_90 AC 1 ms
5,376 KB
testcase_91 AC 1 ms
5,376 KB
testcase_92 AC 1 ms
5,376 KB
testcase_93 AC 0 ms
5,376 KB
testcase_94 AC 1 ms
5,376 KB
testcase_95 AC 1 ms
5,376 KB
testcase_96 AC 1 ms
5,376 KB
testcase_97 AC 1 ms
5,376 KB
testcase_98 AC 1 ms
5,376 KB
testcase_99 AC 1 ms
5,376 KB
testcase_100 AC 1 ms
5,376 KB
testcase_101 AC 1 ms
5,376 KB
testcase_102 AC 1 ms
5,376 KB
testcase_103 AC 1 ms
5,376 KB
testcase_104 AC 1 ms
5,376 KB
testcase_105 AC 1 ms
5,376 KB
testcase_106 AC 1 ms
5,376 KB
testcase_107 AC 1 ms
5,376 KB
testcase_108 AC 1 ms
5,376 KB
testcase_109 AC 1 ms
5,376 KB
testcase_110 AC 1 ms
5,376 KB
testcase_111 AC 1 ms
5,376 KB
testcase_112 AC 1 ms
5,376 KB
testcase_113 AC 1 ms
5,376 KB
testcase_114 AC 1 ms
5,376 KB
testcase_115 AC 1 ms
5,376 KB
testcase_116 AC 1 ms
5,376 KB
testcase_117 AC 1 ms
5,376 KB
testcase_118 AC 1 ms
5,376 KB
testcase_119 AC 1 ms
5,376 KB
testcase_120 AC 1 ms
5,376 KB
testcase_121 AC 1 ms
5,376 KB
testcase_122 AC 1 ms
5,376 KB
testcase_123 AC 1 ms
5,376 KB
testcase_124 AC 1 ms
5,376 KB
testcase_125 AC 1 ms
5,376 KB
testcase_126 AC 1 ms
5,376 KB
testcase_127 AC 1 ms
5,376 KB
testcase_128 AC 1 ms
5,376 KB
testcase_129 AC 1 ms
5,376 KB
testcase_130 AC 1 ms
5,376 KB
testcase_131 AC 1 ms
5,376 KB
testcase_132 AC 1 ms
5,376 KB
testcase_133 AC 1 ms
5,376 KB
testcase_134 AC 1 ms
5,376 KB
testcase_135 AC 1 ms
5,376 KB
testcase_136 AC 1 ms
5,376 KB
testcase_137 AC 1 ms
5,376 KB
testcase_138 AC 1 ms
5,376 KB
testcase_139 AC 1 ms
5,376 KB
testcase_140 AC 1 ms
5,376 KB
testcase_141 AC 1 ms
5,376 KB
testcase_142 AC 1 ms
5,376 KB
testcase_143 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub use __cargo_equip::prelude::*;

use algebraic::{algebra, monoid};
#[allow(unused_imports)]
use proconio::{
    input,
    marker::{Bytes, Chars, Usize1},
};
use union_find_component_sum::UnionFindComponentSum;

algebra!(M, usize);
monoid!(M, 0, |a, b| a ^ b);

fn main() {
    input! {
        n: usize,
        mut p: [Usize1; n - 1],
        s: Bytes,
        m: usize,
        uv: [(Usize1, Usize1); m],
    }
    p.insert(0, !0);
    let mut a = vec![0; n];
    for i in 1..n {
        let x = (s[i - 1] == b'#') as usize;
        a[i] = x;
        a[p[i]] ^= x;
    }
    let mut uf = UnionFindComponentSum::<M>::new(n, &a);
    for &(u, v) in &uv {
        uf.merge(u, v);
    }
    println!(
        "{}",
        if (0..n).all(|i| uf.sum(i) == 0) {
            "Yes"
        } else {
            "No"
        }
    );
}

// The following code was expanded by `cargo-equip`.

///  # Bundled libraries
/// 
///  - `algebraic 0.1.0 (path+████████████████████████████████████████████████████████)`                                    published in **missing** licensed under `CC0-1.0` as `crate::__cargo_equip::crates::algebraic`
///  - `union-find-component-sum 0.1.0 (path+████████████████████████████████████████████████████████████████████████████)` published in **missing** licensed under `CC0-1.0` as `crate::__cargo_equip::crates::union_find_component_sum`
#[cfg_attr(any(), rustfmt::skip)]
#[allow(unused)]
mod __cargo_equip {
    pub(crate) mod crates {
        pub mod algebraic {pub use crate::__cargo_equip::macros::algebraic::*;pub trait Algebra{type S;}pub trait Act:Algebra{type X;fn act(f:&Self::S,x:&Self::X)->Self::X;}pub trait Monoid:Algebra{fn e()->Self::S;fn op(x:&Self::S,y:&Self::S)->Self::S;}pub trait Group:Monoid{fn inv(x:&Self::S)->Self::S;}pub trait Zero{fn zero()->Self;fn is_zero(&self)->bool;}pub trait One{fn one()->Self;fn is_one(&self)->bool;}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_algebra{($ident:ident,$ty:ty)=>{#[derive(Clone)]enum$ident{}impl$crate::__cargo_equip::crates::algebraic::Algebra for$ident{type S=$ty;}};}macro_rules!algebra{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_algebra!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_act{($ident:ident,$tar:ty,$act:expr)=>{impl$crate::__cargo_equip::crates::algebraic::Act for$ident{type X=$tar;#[inline]fn act(f:&Self::S,x:&Self::X)->Self::X{$act(f,x)}}};}macro_rules!act{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_act!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_monoid{($ident:ident,$e:expr,$op:expr)=>{impl$crate::__cargo_equip::crates::algebraic::Monoid for$ident{#[inline]fn e()->Self::S{$e}#[inline]fn op(x:&Self::S,y:&Self::S)->Self::S{$op(x,y)}}};}macro_rules!monoid{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_monoid!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_group{($ident:ident,$e:expr,$op:expr,$inv:expr)=>{impl$crate::__cargo_equip::crates::algebraic::Monoid for$ident{#[inline]fn e()->Self::S{$e}#[inline]fn op(x:&Self::S,y:&Self::S)->Self::S{$op(x,y)}}impl$crate::__cargo_equip::crates::algebraic::Group for$ident{#[inline]fn inv(x:&Self::S)->Self::S{$inv(x)}}};}macro_rules!group{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_group!{$($tt)*})}macro_rules!impl_zero_one{($($t:ty)*)=>{$(impl$crate::__cargo_equip::crates::algebraic::Zero for$t{fn zero()->Self{0}fn is_zero(&self)->bool{*self==0}}impl$crate::__cargo_equip::crates::algebraic::One for$t{fn one()->Self{1}fn is_one(&self)->bool{*self==1}})*};}impl_zero_one!(usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128);}
        pub mod union_find_component_sum {use crate::__cargo_equip::preludes::union_find_component_sum::*;use std::mem::swap;use algebraic::Monoid;#[derive(Clone)]pub struct UnionFindComponentSum<M>where M:Monoid,M::S:Clone,{par:Vec<i32>,sum:Vec<M::S>,cnt:usize,}impl<M>UnionFindComponentSum<M>where M:Monoid,M::S:Clone,{pub fn new(n:usize,a:&[M::S])->Self{Self{par:vec![-1;n],sum:a.to_vec(),cnt:n,}}pub fn len(&self)->usize{self.par.len()}pub fn count(&self)->usize{self.cnt}pub fn merge(&mut self,x:usize,y:usize)->bool{let mut x=self.leader(x);let mut y=self.leader(y);if x==y{return false;}self.cnt-=1;if-self.par[x]< -self.par[y]{swap(&mut x,&mut y);}self.par[x]+=self.par[y];self.sum[x]=M::op(&self.sum[x],&self.sum[y]);self.par[y]=x as i32;true}pub fn leader(&mut self,x:usize)->usize{let mut v=x;while self.par[v]>=0{v=self.par[v]as usize;}let mut u=x;while self.par[u]>=0{let t=self.par[u]as usize;self.par[u]=v as i32;u=t;}u}pub fn same(&mut self,x:usize,y:usize)->bool{self.leader(x)==self.leader(y)}pub fn size(&mut self,x:usize)->usize{let x=self.leader(x);-self.par[x]as usize}pub fn groups(&mut self)->Vec<Vec<usize>>{let mut res=vec![vec![];self.len()];for x in 0..self.len(){res[self.leader(x)].push(x);}res.into_iter().filter(|g|g.len()>0).collect()}pub fn sum(&mut self,x:usize)->M::S{let x=self.leader(x);self.sum[x].clone()}}}
    }

    pub(crate) mod macros {
        pub mod algebraic {pub use crate::{__cargo_equip_macro_def_algebraic_act as act,__cargo_equip_macro_def_algebraic_algebra as algebra,__cargo_equip_macro_def_algebraic_group as group,__cargo_equip_macro_def_algebraic_monoid as monoid};}
        pub mod union_find_component_sum {}
    }

    pub(crate) mod prelude {pub use crate::__cargo_equip::crates::*;}

    mod preludes {
        pub mod algebraic {}
        pub mod union_find_component_sum {pub(in crate::__cargo_equip)use crate::__cargo_equip::crates::algebraic;}
    }
}
0