use std::str::FromStr; use std::io::{BufRead, stdin, Stdin}; use std::collections::{VecDeque, HashMap, BTreeSet, BinaryHeap, BTreeMap}; use std::convert::TryFrom; use std::cmp::min; const MOD: usize = 998244353; fn main() { let mut sc = Scanner::new(); let n = sc.read_usize(); let m = sc.read_usize(); let a = sc.read_vec::(n); let mut graph = (0..n).map(|_| Vec::::new()).collect::>(); for _ in 0..m { let a = sc.read_usize(); let b = sc.read_usize(); graph[a-1].push(b-1); graph[b-1].push(a-1); } let mut is_on = vec![false; n]; let k = sc.read_usize(); for _ in 0..k { let b = sc.read_usize(); is_on[b - 1] = true; } let mut list = (0..n).map(|i| (a[i], i)).collect::>(); list.sort(); let mut ans = Vec::::new(); for (_, i) in list{ if !is_on[i] { continue; } is_on[i] = false; ans.push(i + 1); for j in &graph[i] { if a[i] < a[*j] { is_on[*j] = !is_on[*j]; } } } if is_on.iter().any(|s| *s) { println!("-1"); return; } println!("{}", ans.len()); for v in ans { println!("{}", v); } } struct Scanner { sep: char, inputs: VecDeque, cin: Stdin, } #[allow(unused)] impl Scanner { pub fn new() -> Scanner { Self::from_sep(' ') } pub fn from_sep(ch: char) -> Scanner { Scanner { sep: ch, inputs: VecDeque::new(), cin: stdin(), } } pub fn read(&mut self) -> T { let mut tries = 0; let cin_base = &mut self.cin; let cin = &mut cin_base.lock(); while self.inputs.is_empty() { if tries == 3 { panic!("3 Blank lines found."); } let mut str: String = String::new(); cin.read_line(&mut str).unwrap(); for s in str.trim_end().split(self.sep) { &self.inputs.push_back(String::from(s)); } tries += 1; } let s: String = String::from(&self.inputs.pop_front().unwrap()); s.parse::().ok() .expect("Failed to parse token.") } pub fn read_i32(&mut self) -> i32 { self.read() } pub fn read_i64(&mut self) -> i64 { self.read() } pub fn read_usize(&mut self) -> usize { self.read() } pub fn read_vec(&mut self, n: usize) -> Vec { (0..n).map(|_| self.read()).collect::>() } pub fn read_chars(&mut self) -> Vec { self.read::().chars().collect::>() } }