C - Peaks 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 300

問題文

AtCoder丘陵には N 個の展望台があり、展望台 i の標高は H_i です。 また、異なる展望台どうしを結ぶ M 本の道があり、道 j は展望台 A_j と展望台 B_j を結んでいます。

展望台 i が良い展望台であるとは、展望台 i から一本の道を使って辿り着けるどの展望台よりも展望台 i の方が標高が高いことをいいます。 展望台 i から一本の道を使って辿り着ける展望台が存在しない場合も、展望台 i は良い展望台であるといいます。

良い展望台がいくつあるか求めてください。

制約

  • 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
  • 同じ展望台の組を結ぶ道が複数あることもある。
  • 入力中の値はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

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

出力

良い展望台の数を出力せよ。


入力例 1

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

出力例 1

2
  • 展望台 1 から一本の道を使って辿り着ける展望台は展望台 3 ですが、展望台 1 の標高は展望台 3 の標高より高くないため、展望台 1 は良い展望台ではありません。

  • 展望台 2 から一本の道を使って辿り着ける展望台は展望台 3 と展望台 4 ですが、展望台 2 の標高は展望台 3 の標高より高くないため、展望台 2 は良い展望台ではありません。

  • 展望台 3 から一本の道を使って辿り着ける展望台は展望台 1 と展望台 2 ですが、展望台 3 の標高は展望台 1 の標高より高く、かつ展望台 2 の標高より高いため、展望台 3 は良い展望台です。

  • 展望台 4 から一本の道を使って辿り着ける展望台は展望台 2 ですが、展望台 4 の標高は展望台 2 の標高より高いため、展望台 4 は良い展望台です。

展望台 3 と展望台 4 が良い展望台なので、良い展望台の数は 2 です。


入力例 2

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

出力例 2

3

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