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 C (GCC 9.2.1) (judge verdict: Wrong Answer)

//============================================================================
// Name        : ABC166C.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <stdio.h>

int main() {
	int i, n, m, s, a, b, tempah, tempbh, tempa, tempb;
	int rs, ans = 0;
	int view1[1001];
	int view2[1001];
	int view3[1001];
	int view4[1001];
	int view5[1001];
	int view6[1001];
	int view7[1001];
	int view8[1001];
	int view9[1001];
	int view10[1001];
	int rview1[1001];
	int rview2[1001];
	int rview3[1001];
	int rview4[1001];
	int rview5[1001];
	int rview6[1001];
	int rview7[1001];
	int rview8[1001];
	int rview9[1001];
	int rview10[1001];

	scanf("%d %d", &n, &m);
	s = 1;
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view1[i]);
			s++;
		}
	}
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view2[i]);
			s++;
		}
	}
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view3[i]);
			s++;
		}
	}
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view4[i]);
			s++;
		}
	}
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view5[i]);
			s++;
		}
	}
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view6[i]);
			s++;
		}
	}
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view7[i]);
			s++;
		}
	}
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view8[i]);
			s++;
		}
	}
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view9[i]);
			s++;
		}
	}
	for (i = 0; i < 1000; ++i) {
		if (s <= n) {
			scanf("%d", &view10[i]);
			s++;
		}
	}

	for (i = 1; i <= m; ++i) {
		scanf("%d %d", &a, &b);
		a--;
		b--;
		tempa = a / 1000;
		tempb = b / 1000;
		switch (tempa) {
		case 0:
			tempah = view1[a % 1000];
			break;
		case 1:
			tempah = view2[a % 1000];
			break;
		case 2:
			tempah = view3[a % 1000];
			break;
		case 3:
			tempah = view4[a % 1000];
			break;
		case 4:
			tempah = view5[a % 1000];
			break;
		case 5:
			tempah = view6[a % 1000];
			break;
		case 6:
			tempah = view7[a % 1000];
			break;
		case 7:
			tempah = view8[a % 1000];
			break;
		case 8:
			tempah = view9[a % 1000];
			break;
		case 9:
			tempah = view10[a % 1000];
			break;
		default:
			break;
		}
		switch (tempb) {
		case 0:
			tempbh = view1[b % 1000];
			break;
		case 1:
			tempbh = view2[b % 1000];
			break;
		case 2:
			tempbh = view3[b % 1000];
			break;
		case 3:
			tempbh = view4[b % 1000];
			break;
		case 4:
			tempbh = view5[b % 1000];
			break;
		case 5:
			tempbh = view6[b % 1000];
			break;
		case 6:
			tempbh = view7[b % 1000];
			break;
		case 7:
			tempbh = view8[b % 1000];
			break;
		case 8:
			tempbh = view9[b % 1000];
			break;
		case 9:
			tempbh = view10[b % 1000];
			break;
		default:
			break;
		}
		if (tempah < tempbh) {
			rs = a;
		} else if (tempah < tempbh) {
			rs = b;
		} else if (tempah == tempbh) {
			rs = a;
			switch (rs / 1000) {
			case 0:
				++rview1[rs % 1000];
				break;
			case 1:
				++rview2[rs % 1000];
				break;
			case 2:
				++rview3[rs % 1000];
				break;
			case 3:
				++rview4[rs % 1000];
				break;
			case 4:
				++rview5[rs % 1000];
				break;
			case 5:
				++rview6[rs % 1000];
				break;
			case 6:
				++rview7[rs % 1000];
				break;
			case 7:
				++rview8[rs % 1000];
				break;
			case 8:
				++rview9[rs % 1000];
				break;
			case 9:
				++rview10[rs % 1000];
				break;
			default:
				break;
			}
			rs = b;
		}
		switch (rs / 1000) {
		case 0:
			++rview1[rs % 1000];
			break;
		case 1:
			++rview2[rs % 1000];
			break;
		case 2:
			++rview3[rs % 1000];
			break;
		case 3:
			++rview4[rs % 1000];
			break;
		case 4:
			++rview5[rs % 1000];
			break;
		case 5:
			++rview6[rs % 1000];
			break;
		case 6:
			++rview7[rs % 1000];
			break;
		case 7:
			++rview8[rs % 1000];
			break;
		case 8:
			++rview9[rs % 1000];
			break;
		case 9:
			++rview10[rs % 1000];
			break;
		default:
			break;
		}
	}

	s = 0;
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview1[i] == 0) {
			ans++;
		}
		s++;
	}
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview2[i] == 0) {
			ans++;
		}
		s++;
	}
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview3[i] == 0) {
			ans++;
		}
		s++;
	}
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview4[i] == 0) {
			ans++;
		}
		s++;
	}
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview5[i] == 0) {
			ans++;
		}
		s++;
	}
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview6[i] == 0) {
			ans++;
		}
		s++;
	}
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview7[i] == 0) {
			ans++;
		}
		s++;
	}
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview8[i] == 0) {
			ans++;
		}
		s++;
	}
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview9[i] == 0) {
			ans++;
		}
		s++;
	}
	for (i = 0; i < 1000; ++i) {
		if (s < n && rview10[i] == 0) {
			ans++;
		}
		s++;
	}
	printf("%d", ans);
	return 0;
}