pub mod scanner { pub struct Scanner { buf: Vec, } impl Scanner { pub fn new() -> Self { Self { buf: vec![] } } pub fn new_from(source: &str) -> Self { let source = String::from(source); let buf = Self::split(source); Self { buf } } pub fn next(&mut self) -> T { loop { if let Some(x) = self.buf.pop() { return x.parse().ok().expect(""); } let mut source = String::new(); std::io::stdin().read_line(&mut source).expect(""); self.buf = Self::split(source); } } fn split(source: String) -> Vec { source .split_whitespace() .rev() .map(String::from) .collect::>() } } } use crate::scanner::Scanner; #[derive(Clone, Copy)] struct BitSet([u64; 313]); impl BitSet { fn new() -> Self { Self([0; 313]) } fn set(&mut self, index: usize, b: bool) { let i = index / 64; let j = index % 64; let mask = 1u64 << j; if b { self.0[i] |= mask; } else { self.0[i] &= !mask; } } fn disjoint(&self, rhs: &Self) -> bool { for i in 0..313 { if (self.0[i] & rhs.0[i]).count_ones() > 0 { return false; } } true } } fn main() { let mut scanner = Scanner::new(); let t: usize = 1; for _ in 0..t { solve(&mut scanner); } } fn solve(scanner: &mut Scanner) { let n: usize = scanner.next(); let m: usize = scanner.next(); let mut p = vec![!0; 20000]; let mut w = vec![BitSet::new(); 20000]; let mut f = vec![BitSet::new(); 20000]; for i in 0..n { let x = scanner.next::() - 1; p[i] = x; w[x].set(i, true); } for _ in 0..m { let a = scanner.next::() - 1; let b = scanner.next::() - 1; f[a].set(b, true); f[b].set(a, true); } let q: usize = scanner.next(); for _ in 0..q { let x = scanner.next::() - 1; let y = scanner.next::() - 1; if p[x] == p[y] || w[p[y]].disjoint(&f[x]) { println!("No"); continue; } println!("Yes"); w[p[x]].set(x, false); w[p[y]].set(x, true); p[x] = p[y]; } }