fn main() { let (n, m): (usize, usize) = { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap() ) }; let mut p: Vec = { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|x| x.parse().unwrap()) .collect() }; let mut world = vec![Vec::new(); n]; for i in 0..n { p[i] -= 1; world[p[i]].push(i); } let mut friend = vec![vec![false; n]; n]; for _ in 0..m { let (a, b): (usize, usize) = { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap() ) }; friend[a - 1][b - 1] = true; friend[b - 1][a - 1] = true; } let q: usize = { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().parse().unwrap() }; for _ in 0..q { let mut flag = false; let (mut x, mut y): (usize, usize) = { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap() ) }; x -= 1; y -= 1; if p[x] != p[y] { for &z in world[p[y]].iter() { if friend[x][z] { flag = true; break } } } if flag { for i in 0..world[p[x]].len() { if world[p[x]][i] == x { world[p[x]].remove(i); break } } world[y].push(x); p[x] = p[y]; println!("Yes"); } else { println!("No"); } } }