Problem:
Score : 300 points

Problem Statement

There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.
There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.

Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.
Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.

How many good observatories are there?

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq H_i \leq 10^9

1 \leq A_i,B_i \leq N

A_i \neq B_i

Multiple roads may connect the same pair of observatories.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Print the number of good observatories.

Sample Input 1

4 3
1 2 3 4
1 3
2 3
2 4

Sample Output 1

2

From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.

From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.

From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.

From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.

Thus, the good observatories are Obs. 3 and 4, so there are two good observatories.

Sample Input 2

6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6

Sample Output 2

3

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

#![allow(unused_imports, unused_macros)]

use kyoproio::*;
use std::{
    collections::*,
    io::{self, prelude::*},
    iter,
    mem::{replace, swap},
};

fn main() -> io::Result<()> {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024)
        .spawn(solve)?
        .join()
        .unwrap();
    Ok(())
}

fn solve() {
    let stdin = io::stdin();
    let mut kin = KInput::new(stdin.lock());
    let stdout = io::stdout();
    let mut out = io::BufWriter::new(stdout.lock());
    macro_rules! output { ($($args:expr),+) => { write!(&mut out, $($args),+).unwrap(); }; }
    macro_rules! outputln {
        ($($args:expr),+) => { output!($($args),+); outputln!(); };
        () => { output!("\n"); if cfg!(debug_assertions) { out.flush().unwrap(); } }
    }

    let (n, a, b, c): (usize, usize, usize, usize) = kin.input();
    let mut a = a.min(3);
    let mut b = b.min(3);
    let mut c = c.min(3);
    if a + b + c > 6 {
        a = a.saturating_sub(1);
        b = b.saturating_sub(1);
        c = c.saturating_sub(1);
    }
    let mut dp = vec![[[[false; 4]; 4]; 4]; n + 1];
    dp[0][a][b][c] = true;
    for i in 1..=n {
        let s = kin.str();
        for a in 0..=3 {
            for b in 0..=3 {
                for c in 0..=3 {
                    if !dp[i - 1][a][b][c] {
                        continue;
                    }
                    match s {
                        "AB" => {
                            if a > 0 && b < 3 {
                                dp[i][a - 1][b + 1][c] = true;
                            }
                            if b > 0 && a < 3 {
                                dp[i][a + 1][b - 1][c] = true;
                            }
                        },
                        "AC" => {
                            if a > 0 && c < 3 {
                                dp[i][a - 1][b][c + 1] = true;
                            }
                            if c > 0 && a < 3 {
                                dp[i][a + 1][b][c - 1] = true;
                            }
                        },
                        "BC" => {
                            if b > 0 && c < 3 {
                                dp[i][a][b - 1][c + 1] = true;
                            }
                            if c > 0 && b < 3 {
                                dp[i][a][b + 1][c - 1] = true;
                            }
                        },
                        _ => {}
                    }
                }
            }
        }
    }
    let mut a = 0;
    let mut b = 0;
    let mut c = 0;
    'l: for aa in 0..3 {
        for bb in 0..3 {
            for cc in 0..3 {
                if dp[n][aa][bb][cc] {
                    a = aa;
                    b = bb;
                    c = cc;
                    break 'l;
                }
            }
        }
    }
    if a == 0 && b == 0 && c == 0 {
        outputln!("No");
        return;
    }
    let mut res = Vec::new();
    'r: for i in (1..=n).rev() {
        for da in -1..=1 {
            for db in -1..=1 {
                for dc in -1..=1 {
                    if da + db + dc != 0 || (da == 0 && db == 0 && dc == 0) {
                        continue;
                    }
                    let ta = (a as isize - da) as usize;
                    let tb = (b as isize - db) as usize;
                    let tc = (c as isize - dc) as usize;
                    if ta <= 3 && tb <= 3 && tc <= 3 && dp[i - 1][ta][tb][tc] {
                        res.push(if da == 1 {
                            'A'
                        } else if db == 1 {
                            'B'
                        } else if dc == 1 {
                            'C'
                        } else {
                            panic!();
                        });
                        a = ta;
                        b = tb;
                        c = tc;
                        continue 'r;
                    }
                }
            }
        }
    }
    outputln!("Yes");
    for d in res.into_iter().rev() {
        outputln!("{}", d);
    }
}


// -----------------------------------------------------------------------------
pub mod kyoproio {
    use std::io::prelude::*;
    pub trait Input {
        fn str(&mut self) -> &str;
        fn input<T: InputParse>(&mut self) -> T {
            T::input(self)
        }
        fn iter<T: InputParse>(&mut self) -> Iter<T, Self> {
            Iter(self, std::marker::PhantomData)
        }
        fn seq<T: InputParse, B: std::iter::FromIterator<T>>(&mut self, n: usize) -> B {
            self.iter().take(n).collect()
        }
    }
    pub struct KInput<R> {
        src: R,
        buf: String,
        pos: usize,
    }
    impl<R: BufRead> KInput<R> {
        pub fn new(src: R) -> Self {
            Self {
                src,
                buf: String::with_capacity(1024),
                pos: 0,
            }
        }
    }
    impl<R: BufRead> Input for KInput<R> {
        fn str(&mut self) -> &str {
            loop {
                if self.pos >= self.buf.len() {
                    self.pos = 0;
                    self.buf.clear();
                    if self.src.read_line(&mut self.buf).expect("io error") == 0 {
                        return &self.buf;
                    }
                }
                let range = self.pos
                    ..self.buf[self.pos..]
                        .find(|c: char| c.is_ascii_whitespace())
                        .map(|i| i + self.pos)
                        .unwrap_or_else(|| self.buf.len());
                self.pos = range.end + 1;
                if range.end > range.start {
                    return &self.buf[range];
                }
            }
        }
    }
    pub struct Iter<'a, T, I: ?Sized>(&'a mut I, std::marker::PhantomData<*const T>);
    impl<'a, T: InputParse, I: Input + ?Sized> Iterator for Iter<'a, T, I> {
        type Item = T;
        fn next(&mut self) -> Option<T> {
            Some(self.0.input())
        }
    }
    pub trait InputParse: Sized {
        fn input<I: Input + ?Sized>(src: &mut I) -> Self;
    }
    impl InputParse for Vec<u8> {
        fn input<I: Input + ?Sized>(src: &mut I) -> Self {
            src.str().as_bytes().to_owned()
        }
    }
    macro_rules! from_str_impl {
        { $($T:ty)* } => {
            $(impl InputParse for $T {
                fn input<I: Input + ?Sized>(src: &mut I) -> Self {
                    src.str().parse::<$T>().expect("parse error")
                }
            })*
        }
    }
    from_str_impl! {
        String char bool f32 f64 isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128
    }
    macro_rules! tuple_impl {
        ($H:ident $($T:ident)*) => {
            impl<$H: InputParse, $($T: InputParse),*> InputParse for ($H, $($T),*) {
                fn input<I: Input + ?Sized>(src: &mut I) -> Self {
                    ($H::input(src), $($T::input(src)),*)
                }
            }
            tuple_impl!($($T)*);
        };
        () => {}
    }
    tuple_impl!(A B C D E F G);
}