#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::(); let (n, m) = (v[0], v[1]); let a = read_vec::(); let mut edges = vec![]; let mut g = vec![vec![]; n]; for i in 0..m { let v = read_vec::(); let (u, v) = (v[0] - 1, v[1] - 1); if a[u] < a[v] { edges.push((u, v)); g[u].push(v); } else if a[u] > a[v] { edges.push((v, u)); g[v].push(u); } } let k = read::(); let v = read_vec::(); let mut light = vec![false; n]; for i in v { light[i - 1] = true; } let indexes = topological_sort(&edges, n).unwrap(); let mut answers = vec![]; for i in indexes { if light[i] { for &to in g[i].iter() { light[to] = !light[to]; } answers.push(i); } } println!("{}", answers.len()); for ans in answers { println!("{}", ans + 1); } } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn topological_sort(edges: &Vec<(usize, usize)>, v: usize) -> Option> { let mut h = vec![0; v]; let mut g = vec![Vec::new(); v]; for &(s, t) in edges { g[s].push(t); h[t] += 1; } let mut st: std::collections::VecDeque = std::collections::VecDeque::new(); for i in 0..v { if h[i] == 0 { st.push_back(i); } } let mut sorted_indexes = Vec::new(); while !st.is_empty() { let i = st.pop_back().unwrap(); sorted_indexes.push(i); for &j in g[i].iter() { h[j] -= 1; if h[j] == 0 { st.push_back(j); } } } if sorted_indexes.len() == v { Some(sorted_indexes) } else { None } }