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



Sample input:
4 3
1 2 3 4
1 3
2 3
2 4


Sample output:
2

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = set()
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].add(h[b-1])
        links[h[b-1]].add(h[a - 1])
    cnt = 0
    c = 0
    # visited = set()
    for k, v in links.items():
        if len(v):
            for j in v:
                if k > j:
                    c += 1
            if c == len(v):
                cnt += 1
        else:
            cnt += 1
    # print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = set()
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].add(h[b-1])
        links[h[b-1]].add(h[a - 1])
    cnt = 0
    # visited = set()
    for k, v in links.items():
        if len(v):
            for j in v:
                if k <= j:
                    break
                else:
                    cnt += 1
    # print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int , input().split())
H  = list(map(int , input().split()))
for i in range(M):
  A, B = map(int , input().split())
p = 0
for i in range(1 , N+1):
  q = 0
  C = [0]
  for j in range(M):
    if(A == i):
      b = H[B-1]
      C.append(b)
      q += 1
    elif(B == i):
      a = H[A-1]
      C.append(a)
      q += 1
    else:
      C.append(0) 
  G = max(C)
  if(H[i-1] > G or G==0):
    p += 1
print(p-1)

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = set()
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].add(h[b-1])
        links[h[b-1]].add(h[a - 1])
    cnt = 0
    # visited = set()
    for k, v in links.items():
        if len(v):
            if max(v) <= k:
                cnt += 1
        else:
            cnt += 1
    # print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = set()
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].add(h[b-1])
        links[h[b-1]].add(h[a - 1])
    cnt = 0
    # visited = set()
    for k, v in links.items():
        if len(v):
            if max(v) < k:
                cnt += 1
        else:
            cnt += 1
    # print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = []
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].append(h[b-1])
        links[h[b-1]].append(h[a - 1])
    cnt = 0
    # visited = set()
    for k, v in links.items():
        if len(v):
            if max(v) < k:
                cnt += 1
        else:
            cnt += 1
    # print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
hills = list(map(int, input().split()))

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    try:
        if hills[a] < hills[b]:
            hills.pop(a)
        elif hills[a] > hills[b]:
            hills.pop(b)
    except:
        continue

print(len(hills))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
hills = list(map(int, input().split()))

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    try:
        if hills[a] < hills[b]:
            hills.pop(a)
        elif hills[a] > hills[b]:
            hills.pop(b)
        else:
            hills.pop(a)
            hills.pop(b)
    except:
        continue

print(len(hills))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n, m= list(map(int,input().split()))
h = list(map(int,input().split()))
h = [0] + h

l = defaultdict(list)

while m:
    m -= 1
    a, b = list(map(int,input().split()))
    l[a].append(b)
    l[b].append(a)

ans = 0
for key, arr in l.items():
    if all(h[key] >= h[v] for v in arr):
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
hills = list(map(int, input().split()))

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    try:
        if hills[a] < hills[b]:
            hills.pop(a)
        else:
            hills.pop(b)
    except:
        continue

print(len(hills))

Submission status: Wrong Answer

Solution code:
#二次元配列から重複を取り除く関数
def get_unique_list(seq) :
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

n, m = map(int, input().split()) # 展望台と道の数
h_list = list(map(int, input().split())) # n個の展望台の標高
# どの展望台とどの展望台を結ぶ道があるかのリスト
plane_load_list = []
for i in range(m) :
    plane_load_list.append(list(map(int, input().split())))

# 同じ道は2回以上判定する必要がないので取り除く
load_list = get_unique_list(plane_load_list)

num = [x for x in range(1, n+1)]
bad = []
for i in range(0, len(load_list)) :
    if load_list[i][0] in bad and load_list[i][1] in bad :
        break
    if h_list[load_list[i][0]-1]<h_list[load_list[i][1]-1] :
        bad.append(load_list[i][0])
    else :
        bad.append(load_list[i][1])

bad_value = list(set(bad))
print(len(num)-len(bad_value))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

N, M = [int(x) for x in stdin.readline().rstrip().split()]
# 展望台iの標高
H = [int(x) for x in stdin.readline().rstrip().split()]
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]

dic = {}

for A, B in AB:
    dic[A] = dic.get(A, []) + [B]
    dic[B] = dic.get(B, []) + [A]

ans = 0
for key, values in dic.items():
    flg = True
    for value in values:
        if H[key-1] < H[value-1]:
            flg = False
            break
    if flg:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = []
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].append(h[b-1])
        links[h[b-1]].append(h[a - 1])
    cnt = 0
    visited = set()
    for k, v in links.items():
        for j in v:
            if j not in visited:
                if k < j:
                    cnt += 1
    # print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
N, M = [ int(i) for i in input().strip().split(' ') ]
H    = [ int(i) for i in input().strip().split(' ') ]
paths = []
for _m in range(M):
    path = input().strip().split(' ')
    path = int(path[0]), int(path[1])
    path = path if path[0] < path[1] else (path[1], path[0])
    if path not in paths:
        paths.append(path)
print(paths)
all_paths = []
for path in paths:
    all_paths += path
all_paths = set(all_paths)
count = 0
for n in range(1, N+1):
    is_good = 1
    if n not in all_paths:
        count += is_good
        continue
    for path in paths:
        if n not in list(path):
            continue
        if (path[0] == n):
            if (H[n-1] <= H[path[1]-1]):
                is_good = 0
                break
        else:
            if (H[n-1] <= H[path[0]-1]):
                is_good = 0
                break    
    count += is_good
print(count)

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        v.add(max(h[a-1], h[b-1]))
    print(len(v))


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = [int(h) for h in input().split()]
flag = [1 for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  if H[a-1] < H[b-1]:
    flag[a-1] = 0
  elif H[a-1] > H[b-1]:
    flag[b-1] = 0
print(sum(flag))

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        v.add(b)
    print(len(v))


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
Height = []
Good = []
for i in range(N):
    Height.append(H[i])
    Good.append(0)
for i in range(M):
    A, B = map(int, input().split())
    if Height[A - 1] < Height[B - 1]:
        Good[A - 1] = 1
    if Height[A - 1] > Height[B - 1]:
        Good[B - 1] = 1
    else:
        Good[A - 1] = 1
        Good[B - 1] = 1
n = 0
for i in range(N):
    if Good[i] == 0:
        n += 1
print(n)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
Height = []
Good = []
for i in range(N):
    Height.append(H[i])
    Good.append(0)
for i in range(M):
    A, B = map(int, input().split())
    if Height[A - 1] < Height[B - 1]:
        Good[A - 1] = 1
    else:
        Good[B - 1] = 1
n = 0
for i in range(N):
    if Good[i] == 0:
        n += 1
print(n)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
H = list(map(int, input().split()))
A_B = [list(map(int,input().split())) for i in range(M)]

ans_label = [1]*len(H)

A_B = [[ele[0],ele[1]] if H[ele[0]-1] < H[ele[1]-1] else [ele[1],ele[0]]for ele in A_B]

# A_B.sort(key=lambda x: x[0])

for ele in A_B:
    ans_label[ele[0]-1] = 0

print(sum(ans_label))

Submission status: Wrong Answer

Solution code:
N, M = tuple(int(i) for i in input().split(" "))
height = [int(i) for i in input().split(" ")]
road = []
for i in range(N):
    road.append([])
for i in range(M):
    temp = [int(j) - 1 for j in input().split(" ")]
    road[temp[0]].append(temp[1])
    road[temp[1]].append(temp[0])

goodH = [i for i in range(N)]
ans = 0
for i in range(N):
    if goodH[i]:
        for j in road[i]:
            if height[i] > height[j]:
                goodH[j] = 0
            elif height[i] == height[j]:
                goodH[j] = 0
                break
            else:
                break
        else:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
cnt=[1]*n
for i in range (m):
  a,b=map(int,input().split())
  if h[a-1]>h[b-1]:
    if cnt[a-1]!=0:
      cnt[a-1]=1
      cnt[b-1]=0
      
  elif h[a-1]<h[b-1]:
    if cnt[b-1]!=0:
      cnt[a-1]=0
      cnt[b-1]=1
  else :
    cnt[a-1]=cnt[b-1]=0
print(cnt.count(1))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

# 1 ✕ N
N, M = list(map(int, input().rstrip().split()))

H = list(map(int, input().rstrip().split()))

A = tuple(map(int, input().rstrip().split()) for _ in range(M))


items = dict((i + 1, []) for i in range(N))

for k, v in A:
    items[k].append(v)
    items[v].append(k)

ans = 0
for i in range(N):
    if len(list(filter(lambda x: H[i] > x, items[i + 1]))) == 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

# 1 ✕ N
N, M = list(map(int, input().rstrip().split()))

H = list(map(int, input().rstrip().split()))

A = tuple(map(int, input().rstrip().split()) for _ in range(M))


items = dict((i + 1, []) for i in range(N))

for k, v in A:
    items[k].append(v)
    items[v].append(k)

ans = 0
for i in range(N):
    if len(list(filter(lambda x: H[i] >= x, items[i + 1]))) == 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
temp = input()
temp = temp.split()
N = int(temp[0])
M = int(temp[1])

temp = input()
temp = temp.split()
height = [int(s) for s in temp]
bridge = [0] * N
data = [0] * N

for i in range(M):
  temp = input()
  temp = temp.split()
  A = int(temp[0])
  B = int(temp[1])
  if height[A-1] > height[B-1]:
    data[B-1] = 1
  else:
    data[A-1] = 1
    
  bridge[A-1] = 1
  bridge[B-1] = 1

count = 0
for i in range(N):
  if data[i] == 0 or bridge[i] == 0:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
temp = input()
temp = temp.split()
N = int(temp[0])
M = int(temp[1])

temp = input()
temp = temp.split()
height = [int(s) for s in temp]
bridge = [0] * N
data = [0] * N

for i in range(M):
  temp = input()
  temp = temp.split()
  A = int(temp[0])
  B = int(temp[1])
  if height[A-1] > height[B-1]:
    data[A-1] = 1
  else:
    data[B-1] = 1
  bridge[A-1] = 1
  bridge[B-1] = 1

count = 0
for i in range(N):
  if data[i] == 0 or bridge[i] == 0:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []  
for j in range(M):
    AB.append(input().split())

answer = list(range(1, N+1))

for m in range(M):
  if int(AB[m][0]) in answer or int(AB[m][1]) in answer:
    if H[int(AB[m][0])-1]  >= H[int(AB[m][1])-1] and int(AB[m][1]) in answer:
      answer.remove(int(AB[m][1]))
    elif H[int(AB[m][0])-1] < H[int(AB[m][1])-1] and int(AB[m][0]) in answer:
      answer.remove(int(AB[m][0]))
    
print(len(answer))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=[int(h) for h in input().split()]
AB=[]
cnt=0
for i in range(M):
    A,B=map(int,input().split())
    AB.append([A,B])
def henkan(A,i):
    B=[i]
    for j in range(len(A)):
        if i in A[j]:
            if A[j][0]==i:
                B.append(A[j][1])
            else:
                B.append(A[j][0])
        else:
            pass
    return B
for i in range(N):
    X=henkan(AB,i)
    if all(H[i]>=X[k] for k in range(len(X))):
        cnt+=1
    else:
        pass
print(cnt)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=[int(h) for h in input().split()]
AB=[]
for i in range(M):
    A,B=map(int,input().split())
    AB.append([A,B])
AB=sorted(AB)
cnt=0
CHECK=[1]
for i in range(1,N+1):
    XX=[]
    XX.append(i)
    for j in range(CHECK[-1]-1,M):
        if AB[j][0]<i:
            pass
        elif AB[j][0]==i:
            XX.append(AB[j][1])
        elif AB[j][0]>i:
            CHECK.append(AB[j][0])
            CHECK=sorted(CHECK)
            break
    if all(H[i-1] >= XX[k] for k in range(len(XX))):
        cnt+=1
    else:
        pass
print(cnt)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=[int(h) for h in input().split()]
AB=[]
for i in range(M):
    A,B=map(int,input().split())
    AB.append([A,B])
AB=sorted(AB)
cnt=0
CHECK=[1]
for i in range(1,N+1):
    XX=[]
    XX.append(i)
    for j in range(CHECK[-1]-1,M):
        if AB[j][0]<i:
            pass
        elif AB[j][0]==i:
            XX.append(AB[j][1])
        elif AB[j][0]>i:
            CHECK.append(AB[j][0])
            break
    if all(H[i-1] >= XX[k] for k in range(len(XX))):
        cnt+=1
    else:
        pass
print(cnt)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=[int(h) for h in input().split()]
AB=[]
for i in range(M):
    A,B=map(int,input().split())
    AB.append([A,B])
AB=sorted(AB)
cnt=0
for i in range(1,N+1):
    XX=[]
    XX.append(i)
    for j in range(M):
        if AB[j][0]<i:
            pass
        elif AB[j][0]==i:
            XX.append(AB[j][1])
        elif AB[j][0]>i:
            break
    if all(H[i-1] >= XX[k] for k in range(len(XX))):
        cnt+=1
    else:
        pass
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
h_dict = {}
for i, name in enumerate(h, 1):
    h_dict[i] = name

ab = []
for _ in range(m):
    ab.append(list(map(int, input().split())))

flg_bad = set()
for j in ab:
    if j[0] in flg_bad and j[1] in flg_bad:
        break
    if h_dict[j[0]] < h_dict[j[1]]:
        flg_bad.add(j[0])
    elif h_dict[j[0]] > h_dict[j[1]]:
        flg_bad.add(j[1])
    elif h_dict[j[0]] == h_dict[j[1]]:
        flg_bad.add(j[0])
        flg_bad.add(j[1])


print(len(h) - len(flg_bad))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = []
h = list(map(int, input().split()))
ab = []
for _ in range(m):
    ab.append(list(map(int, input().split())))
ab = dict(ab)

flg_bad = []
for i in range(len(h)):
    for j in ab:
        if h[i] <= j:
            flg_bad.append(1)
            break

print(len(h) - len(flg_bad))

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
l = readl()
p = [[0 for i in range(n + 1)] for j in range(n + 1)]

for i in range(m):
    a, b = readmi()
    p[a][b] = 1
    p[b][a] = 1

f = [0] * (n + 1)
count = 0
def dfs(a):
    flg = True
    global count
    for i in range(n):
        if p[a][i + 1] == 1:
            if f[i + 1] == 0:
                f[i + 1] = 1
                dfs(i + 1)
            if l[a - 1] < l[i]:
                flg = False
    if flg:
        count += 1
dfs(1)
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))

ans = set()
for _ in range(m):
    a, b = map(int, input().split())
    s1, s2 = h[a - 1], h[b - 1]
    ans |= {a} if s1 < s2 else {b}

print(n - len(ans))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
check = [0 for i in range(n)]

for _ in range(m):
    a,b = map(int, input().split())
    if h[a-1]>=h[b-1]:
        check[b-1] += 1
    elif h[a-1]<=h[b-1]:
        check[a-1] += 1
    else:
        pass

ans = sum([c == 0 for c in check])
print(ans)
#print(check)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
not_good=[]
for i in range(m):
  a,b=map(int,input().split())
  if l[a-1]>l[b-1]:
      not_good.append(b)
  if l[a-1]<l[b-1]:
      not_good.append(a)
  else:
    not_good.append(a)
    not_good.append(b)

not_good=set(not_good)
print(n-len(not_good))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))

not_good=[]
for i in range(m):
  a,b=map(int,input().split())
  if l[a-1]>l[b-1]:
    if not b in not_good:
      not_good.append(b)
  if l[a-1]<l[b-1]:
    if not a in not_good:
      not_good.append(a)
  else:
    if not a in not_good:
      not_good.append(a)
    if not b in not_good:
      not_good.append(b)

print(n-len(not_good))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
d={}
for i in range(n):
  d[i+1]=l[i]
not_good=[]
for i in range(m):
  a,b=map(int,input().split())
  if d[a]>d[b]:
    if not b in not_good:
      not_good.append(b)
  if d[a]<d[b]:
    if not a in not_good:
      not_good.append(a)
  else:
    if not a in not_good:
      not_good.append(a)
    if not b in not_good:
      not_good.append(b)

print(n-len(not_good))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
hill=list(range(1,n+1))
l=list(map(int,input().split()))
d={}
for i in range(n):
  d[i+1]=l[i]

for i in range(m):
  a,b=map(int,input().split())
  if d[a]>d[b]:
    if b in hill:
      hill.remove(b)
  if d[a]<d[b]:
    if a in hill:
      hill.remove(a)
  else:
    if a in hill:
      hill.remove(a)
    if b in hill:
      hill.remove(b)

print(len(hill))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
hill=list(range(1,n+1))
l=list(map(int,input().split()))
d={}
for i in range(n):
  d[i+1]=l[i]

for i in range(m):
  a,b=map(int,input().split())
  if d[a]>d[b]:
    if b in hill:
      hill.remove(b)
  if d[a]<d[b]:
    if a in hill:
      hill.remove(a)
  else:
    if a in hill:
      hill.remove(a)
    if b in hill:
      hill.remove(b)
print(len(hill))

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))

ans = [True] * N

H = list(map(int, input().split()))

for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1; b -= 1
    
    if H[a] < H[b]: ans[a] = False
    else: ans[b] = False
        
print(sum(ans))

Submission status: Wrong Answer

Solution code:
N,M = (int(x) for x in input().split())
obs_height = [int(x) for x in input().split()]
good_obs_num = 0
check_list = []

for i in range(M):
  a,b = (int(x) for x in input().split())
  if(a < b):
      good_obs_num += 1
    
print(good_obs_num)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
load_list = []
for m in range(M):
    A, B = map(int, input().split())
    load_list.append((A, B))

highest_list = []
for i in range(N):
    highest_list.append(1)

for m in range(M):
    if H[load_list[m][0] - 1] > H[load_list[m][1] - 1]:
        highest_list[load_list[m][1] - 1] = 0
    elif H[load_list[m][1] - 1] > H[load_list[m][0] - 1]:
        highest_list[load_list[m][0] - 1] = 0

print(highest_list.count(1))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
cnt=[1]*n
for i in range (m):
  a,b=map(int,input().split())
  if h[a-1]>h[b-1]:
    cnt[a-1]=1
    cnt[b-1]=0
  elif h[a-1]<h[b-1]:
    cnt[a-1]=0
    cnt[b-1]=1
  else :
    cnt[a-1]=cnt[b-1]=0
print(cnt.count(1))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split(' '))
heightList = input().split(' ')
checkifBestLT = [True for i in range(N)]
nodeList =[[] for i in range(N)]

for i in range(M):
    nodeA,nodeB = map(int,input().split(' '))
    nodeList[nodeA-1].append(nodeB-1)
    nodeList[nodeB-1].append(nodeA-1)

for i in range(N):
    for j in nodeList[i]:
        if heightList[i] <= heightList[j]:
            checkifBestLT[i] = False
            break
print(sum(checkifBestLT))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split(' '))
heightList = input().split(' ')
checkifBestLT = [1 for i in range(N)]
nodeList =[[] for i in range(N)]

for i in range(M):
    node = input().split(' ')
    nodeList[int(node[0])-1].append(int(node[1])-1)
    nodeList[int(node[1])-1].append(int(node[0])-1)

for i in range(N):
    for j in nodeList[i]:
        if heightList[i] < heightList[j]:
            checkifBestLT[i] = 0
        if heightList[i] == heightList[j]:
            checkifBestLT[i] = 0
            checkifBestLT[j] = 0

print(sum(checkifBestLT))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split(' '))
heightList = input().split(' ')
checkifBestLT = [1 for i in range(N)]
nodeList =[[] for i in range(N)]

for i in range(M):
    node = input().split(' ')
    nodeList[int(node[0])-1].append(int(node[1])-1)
    nodeList[int(node[1])-1].append(int(node[0])-1)

for i in range(N):
    for j in nodeList[i]:
        if heightList[i] <= heightList[j]:
            checkifBestLT[i] = 0
            continue

print(sum(checkifBestLT))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
height=list(map(int,input().split()))
LIST=[]
check=[]
for i in range(m):
  a,b=map(int,input().split())
  ah=height[a-1]
  bh=height[b-1]
  check.append(a)
  check.append(b)
  if ah!=bh:
    LIST.append(a)
    LIST.append(b)
    
    LIST.remove(min(a,b))
    

check=list(set(check))
for i in range(1,n):
  if check.count(i)==0:
    LIST.append(i)
LIST=set(LIST)
print(len(LIST))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
height=list(map(int,input().split()))
LIST=[]
check=[]
for i in range(m):
  a,b=map(int,input().split())
  ah=height[a-1]
  bh=height[b-1]
  if ah!=bh:
    LIST.append(a)
    LIST.append(b)
    check.append(a)
    check.append(b)
    LIST.remove(min(a,b))
check=list(set(check))
for i in range(1,n):
  if check.count(i)==0:
    LIST.append(i)
LIST=set(LIST)
print(len(LIST))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H=list(map(int,input().split()))
ABmap=[[] for i in range(N)]
count=0
for i in range(M):
    A,B=map(lambda x:x-1,map(int,input().split()))
    ABmap[A].append(H[B])
    ABmap[B].append(H[A])
        
for i in range(N):
    if len(ABmap[i])==0:
        count+=1
    elif max(ABmap[i])<H[i]:
        count+=1
   # print(ABmap[i])
    #print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n, m = [int(i) for i in stdin.readline().split()]
h_ls = [int(i) for i in stdin.readline().split()]

par = list(range(n))
ns = [1 for i in range(n)]

def find(x):
    ls = []
    while x != par[x]:
        ls.append(x)
        x = par[x]
    for l in ls:
        par[l] = x
    return x

def unite(x, y):
    x = find(x)
    y = find(y)
    if x != y:
        par[x] = y
        ns[y] += ns[x]

def is_same(x, y):
    if find(x) == find(y):
        return True
    else:
        return False

for i in range(m):
    a, b = [int(i) for i in stdin.readline().split()]
    a -= 1
    b -= 1
    unite(a, b)
dic = dict()
for i, j in enumerate(par):
    if dic.get(j) is None:
        dic[j] = []
    dic[j].append(h_ls[i])
dic = {i : sorted(j) for i, j in dic.items()}
dic = {i : j for i, j in dic.items() if len(j) == 1 or j[-1] != j[-2]}
print(len(dic))

Submission status: Wrong Answer

Solution code:
from sys import stdin
n, m = [int(i) for i in stdin.readline().split()]
h_ls = [int(i) for i in stdin.readline().split()]

par = list(range(n))
ns = [1 for i in range(n)]

def find(x):
    ls = []
    while x != par[x]:
        ls.append(x)
        x = par[x]
    for l in ls:
        par[l] = x
    return x

def unite(x, y):
    x = find(x)
    y = find(y)
    if x != y:
        par[x] = y
        ns[y] += ns[x]

def is_same(x, y):
    if find(x) == find(y):
        return True
    else:
        return False

for i in range(m):
    a, b = [int(i) for i in stdin.readline().split()]
    a -= 1
    b -= 1
    unite(a, b)
print(len(set(par)))