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:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [[] for _ in range(n)]
check = [False for _ in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  ab[a-1].append(b)
  ab[b-1].append(a)

for j in range(n):
  for k in ab[j]:
    if k < h[j]:
      check[j] = True

print(check.count(True))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ls = list(map(int,input().split()))
dir = [list(map(int,input().split())) for _ in range(m)]
k = 0
p = 0
for i in range(1,n+1):
    new = [e for e in dir if i in e]
    print(new)
    if new == []:
        k += 1
    else:
        for j in range(len(new)):
            if new[j][0] != i:
                (new[j][0],new[j][1]) = (new[j][1],new[j][0])
                print(new[j])
            if ls[new[j][0]-1]>ls[new[j][1]-1]:
                p += 1
            if p == len(new):
                k += 1
        p = 0
print(k)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
tree = list(map(int,input().split())) #比較用
tree_sub = tree #データの削除用
for i in range(M):
    a,b = map(int,input().split())
    if (tree[a-1] > tree[b-1]):
        tree_sub[b-1] = 0
    elif (tree[a-1] < tree[b-1]):
        tree_sub[a-1] = 0
print(len(tree_sub)-tree_sub.count(0))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
tree = list(map(int,input().split())) #比較用
tree_sub = tree #データの削除用
for i in range(M):
    a,b = map(int,input().split())
    if (tree[a-1] > tree[b-1]) and (tree[b-1]== tree_sub[b-1]):
        tree_sub[b-1] = 0
    elif (tree[a-1] < tree[b-1]) and (tree[a-1] == tree_sub[a-1]):
        tree_sub[a-1] = 0
print(len(tree_sub)-tree_sub.count(0))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
tree = list(map(int,input().split())) #比較用
tree_sub = tree #データの削除用
count = 0
for i in range(M):
    a,b = map(int,input().split())
    if (tree[a-1] > tree[b-1]) and (tree[b-1]== tree_sub[b-1]):
        tree_sub[b-1] = 0
    elif (tree[a-1] < tree[b-1]) and (tree[a-1] == tree_sub[a-1]):
        tree_sub[a-1] = 0
for i in range(N):
    if tree_sub[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 = [list(map(int, input().split())) for i in range(m)]

s = 0
rem = []
for i in range(1, n + 1):
    if i in rem:
        continue
    tf = True
    k = i
    for j in range(len(ab)):
        if ab[j][0] == i:
            k = ab[j][1]
        elif ab[j][1] == i:
            k = ab[j][0]
        if (k != i) & (h[i - 1] <= h[k - 1]):
            tf = False
            del ab[j]
            break
        elif (k != 1) & (h[i - 1] > h[k - 1]):
            rem.append(k)
    if tf == True:
        s += 1

print(s)

Submission status: Wrong Answer

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

s = 0
for i in range(1, n + 1):
    tf = True
    k = i
    for j in range(len(ab)):
        if ab[j][0] == i:
            k = ab[j][1]
        elif ab[j][1] == i:
            k = ab[j][0]
        if (k != i) & (h[i - 1] <= h[k - 1]):
            tf = False
            del ab[j]
            break
    if tf == True:
        s += 1

print(s)

Submission status: Wrong Answer

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

dp=[1 for i in range(n)]
for i in range(m):
    if h[road[i][0]-1]>h[road[i][1]-1]:
        dp[road[i][1]-1]*=0
    else:
        dp[road[i][0]-1]*=0
ans=0
for i in range(n):
    if dp[i]>0:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

dp=[int(10^9) for i in range(n)]
for i in range(m):
    if h[road[i][0]-1]>=h[road[i][1]-1]:
        dp[road[i][1]-1]*=0
    else:
        dp[road[i][0]-1]*=0
ans=0
for i in range(n):
    if dp[i]>0:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
    
Q=[0]*N
for i in range(M):
    if H[A[i][0]-1]>=H[A[i][1]-1]:
        Q[A[i][1]-1]=-10**5
    elif H[A[i][0]-1]<=H[A[i][1]-1]:
        Q[A[i][0]-1]=-10**5
n = sum(x>=0 for x in Q)
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
    
Q=[0]*N
for i in range(M):
    if H[A[i][0]-1]>H[A[i][1]-1]:
        Q[A[i][0]-1]=1
        Q[A[i][1]-1]=-10**5
    elif H[A[i][0]-1]<H[A[i][1]-1]:
        Q[A[i][0]-1]=-10**5
        Q[A[i][1]-1]=1
    elif  H[A[i][0]-1]==H[A[i][1]-1]:
        Q[A[i][0]-1]=-10**5
        Q[A[i][1]-1]=-10**5
        
        
n = sum(x>=0 for x in Q)
print(n)

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int, input().split())
    g = [[] for i in range(n+1)]
    hl = [[] for i in range(n+1)] 
    h = [0]
    h.extend(list(map(int, input().split())))
    for i in range(m):
        a, b = map(int, input().split())
        g[a].append(b)
        g[b].append(a)
    g[0].append(0)
    for i, gi in enumerate(g):
        for j, gj in enumerate(gi):
            if gj is None:
                continue
            hl[i].append(h[gj])
    min_hl = list()
    for i in hl:
        if i == []:
            min_hl.append(0)
        else:
            min_hl.append(min(i))
    res = len([x - y for (x, y) in zip(h, min_hl) if x - y > 0 ])
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M = [int(x) for x in input().split()]
P = dict([(i,True) for i in range(1,N+1)])
H = [0] + [int(x) for x in input().split()]
for m in range(M):
    A,B = [int(x) for x in input().split()]
    if H[A] >= H[B]:
        P[B] = False
    if H[B] >= H[A]:
        P[A] = False

print(P)
print(sum(list(P.values())))

Submission status: Wrong Answer

Solution code:
import math
import itertools
x=input()
x0=x.split()
n=int(x0[0])
m=int(x0[1])
h=input()
h0=h.split()
h0=[int(n) for n in h0]
l=list()
l1=list()
z=0
for i in range(m):
    ab=input()
    ab0=ab.split()
    a=int(ab0[0])
    b=int(ab0[1])
    p=[a,b]
    l.append(p)
    l1.extend(p)
for i in range(n):
    l2=([s for s, x in enumerate(l1) if x==i])
    if l2==[]:
        z=z+1
    else:
        l3=list(map(lambda x:l[math.floor(x/2)],l2))
        l3=list(itertools.chain.from_iterable(l3))
        l3=[s for s in l3 if not s==i]
        l4=max(list(map(lambda x:h0[x-1],l3)))
        if l4<h0[i]:
            z=z+1
print(z)

Submission status: Wrong Answer

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

dic = {}
for i in range(M):
    A, B = map(int,input().split())
    H_max = max(H[A-1],H[B-1])
    H_min = min(H[A-1],H[B-1])
    if H_max in dic.keys():
        dic[H_max] += 1
    elif not(H[A-1] == H[B-1]):
        dic[H_max] = 1
    if H_min in dic.keys() and not(H_max == H_min):
        del dic[H_min]

print(len(dic.keys()))

Submission status: Wrong Answer

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

dic = {}
for i in range(M):
    A, B = map(int,input().split())
    H_max = max(H[A-1],H[B-1])
    H_min = min(H[A-1],H[B-1])
    if H_max in dic.keys():
        dic[H_max] += 1
    else:
        dic[H_max] = 1
    if H_min in dic.keys() and not(H_max == H_min):
        del dic[H_min]

print(len(dic.keys()))

Submission status: Wrong Answer

Solution code:
N, M = (int(x) for x in input().split())
H = list(map(int, input().split()))

bridge = []
for i in range(M):
  a = list(map(int, input().split()))
  bridge.append(a)
 
no = [H.index(max(H))+1, H.index(min(H))+1]
ok = [H.index(max(H))+1]
for j in bridge:
  no += [H.index(min(H[j[0]-1], H[j[1]-1]))]
  if H.index(max(H[j[0]-1], H[j[1]-1]))+1 not in ok:
    ok += [H.index(max(H[j[0]-1], H[j[1]-1]))+1]
  if len(no) == N:
    print(len(ok))
    exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

h=list(map(int,input().split()))
ans=[0]*n

for i in range(m):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if a==b:
    ans[a]+=1
    ans[b]+=1
  elif a>b:
    ans[b]+=1
  else:
    ans[a]+=1

print(ans.count(0))

Submission status: Wrong Answer

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

print(ac.count(1))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
l = [1 for i in range(len(H))]
A = []
B = []
for _ in range(M):
    temp = list(map(int, input().split()))
    A.append(temp[0])
    B.append(temp[1])

for i in range(M):
    if H[A[i]-1] > H[B[i]-1]:
        l[B[i]-1] = 0
    elif H[A[i]-1] < H[B[i]-1]:
        l[A[i]-1] = 0
    else:
        l[A[i]-1] = 0
        l[B[i]-1] = 0
print(len(H)-sum(l))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
h_list = list(map(int, input().split()))
good_list = [1 for i in range(n)]
for i in range(m):
  _a,_b = map(int, input().split())
  if h_list[_a-1] == h_list[_b-1]:
    pass
  elif h_list[_a-1] > h_list[_b-1]:
    good_list[_b-1] = 0
  else:
    good_list[_a-1] = 0
print(sum(good_list))

Submission status: Wrong Answer

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

for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] < H[b-1]:
      c[a-1] = 1
    elif H[a-1] > H[b-1]:
      c[b-1] = 1
    elif H[a-1] != H[b-1]:
      c[a-1] = 1
      c[b-1] = 1

print(c.count(1))

Submission status: Wrong Answer

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

num_ok = []
num_false = []
for i in range(m):
  if h[j[i][0] -1] > h[j[i][1] - 1]:
    num_ok.append(j[i][0])
  else:
    num_false.append(j[i][0])
for i in range(m):
  if h[j[i][1] - 1] > h[j[i][0] - 1]:
    num_ok.append(j[i][1])
  else:
    print(j[i][1])
    num_false.append(j[i][1])

set_num_ok = set(num_ok)
set_num_false = set(num_false)
count = 0

for i in range(1,n+1):
  if i not in set_num_ok and i not in set_num_false:
    count+=1
  else:
    continue
for num in set_num_ok:
  if num in set_num_false:
    continue
  else:
    count+=1
print(count)

Submission status: Wrong Answer

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

lose_list = []
for i in range(M):
    if tower_height[tower_route[i][0] - 1] > tower_height[tower_route[i][1] - 1]:
        lose_list.append(tower_height[tower_route[i][1]-1])
        try:
            lose_list.remove(tower_height[tower_route[i][0]-1])
        except ValueError:
            continue
    elif tower_height[tower_route[i][0] - 1] < tower_height[tower_route[i][1] - 1]:
        lose_list.append(tower_height[tower_route[i][0]-1])
        try:
            lose_list.remove(tower_height[tower_route[i][1]-1])
        except ValueError:
            continue

print(len(list(set(tower_height) - set(lose_list))))

Submission status: Wrong Answer

Solution code:
n,m = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]

g = [ [] for _ in range(n)]

for _ in range(m):
    a,b = [int(x)-1 for x in input().split()]
    g[a].append(b)
    g[b].append(a)

vis = [False]*n

cnt = 0

for i in range(n):
    if not vis[i]:
        vis[i] = True
        
        gtr = [ H[i] > x for x in g[i] ]
        if all(gtr):
            cnt+=1
            for x in g[i]:vis[x] = True


print(cnt)

Submission status: Wrong Answer

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

for i in range(M):
  a, b = map(int,input().split())
  if(H[a-1] > H[b-1]):
    c[b-1] = 0
  else:
    c[a-1] = 0
print(c.count(1))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix
# CreatedDate:  2020-05-28 18:06:34 +0900
# LastModified: 2020-05-28 22:11:30 +0900
#


import os
import sys
#import numpy as np
#import pandas as pd


def main():
    n,m = map(int,input().split())
    h = list(map(int,input().split()))
    h_dic = {}
    for i in range(1,n+1):
        h_dic[i]=h[i-1]
#    print(h_dic)

    h_dic_sort = sorted(h_dic.items(),key=lambda x:x[1])
    path = [[] for _ in range(n+1)]
    for _ in range(m):
        a,b = map(int,input().split())
        path[a].append(b)
        path[b].append(a)

#    print(path)

    marking = [0]*(n+1)
    count=0
    while h_dic_sort:
        u,u_height = h_dic_sort.pop()
#        print("u:{}".format(u))
        if marking[u]==1:
            continue
#        print("v:",end="")
        for i,v in enumerate(path[u]):
#            print("{}".format(v),end="")
            if u_height>h[v-1]:
                marking[v]+=1
            else:
                break
#        print("i:{}".format(i))
        if i+1==len(path[u]):
            count+=1
#        print(marking)
#        print("count:{}".format(count))
    for l in path:
        if len(l)==0:
            count+=1
    print(count-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, M = (int(x) for x in input().split())
H = list(map(int, input().split()))

GT = [0 for i in range(N)]

for i in range(M):
    A, B = (int(x) for x in input().split())
    if H[A-1] != H[B-1]:
        L = max(H[A-1], H[B-1])
        GT[H.index(L)] = 1
    
print(sum(GT))

Submission status: Wrong Answer

Solution code:
N, M = (int(x) for x in input().split())
H = list(map(int, input().split()))

GT = [1 for i in range(N)]

for i in range(M):
    A, B = (int(x) for x in input().split())
    if GT[A-1] == 0 and GT[B-1] == 0:
        continue
    if H[A-1] != H[B-1]:
        L = min(H[A-1], H[B-1])
        GT[H.index(L)] = 0
    else:
        GT[A-1] = 0
        GT[B-1] = 0
    
print(sum(GT))

Submission status: Wrong Answer

Solution code:
N, M = (int(x) for x in input().split())
H = list(map(int, input().split()))

GT = [1 for i in range(N)]

for i in range(M):
    A, B = (int(x) for x in input().split())
    if H[A-1] != H[B-1]:
        L = min(H[A-1], H[B-1])
        GT[H.index(L)] = 0
    else:
        GT[A-1] = 0
        GT[B-1] = 0
    
print(sum(GT))

Submission status: Wrong Answer

Solution code:
N, M = (int(x) for x in input().split())
H = list(map(int, input().split()))

GT = [1 for i in range(N)]

for i in range(M):
    A, B = (int(x) for x in input().split())
    if H[A-1] != H[B-1]:
        L = min(H[A-1], H[B-1])
        GT[H.index(L)] = 0
    else:
        GT[A-1] = 0
        GT[B-1] = 0
    
print(GT)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H=list(map(int,input().split()))
l = [[]*i for i in range(N)]
print(l)
for i in range(M):
    A,B=map(int,input().split())
    l[A-1].append(B)
    l[B-1].append(A)
ans=0
for j in range(N):
    if all(H[elem-1] < H[j] for elem in l[j])==True:
        ans +=1
print(ans)

Submission status: Wrong Answer

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

taller_set = set()
smaller_set = set()
all_tower_with_roads = set()
for i in range(M):
    A, B = map(int, input().split())
    A -=1
    B -=1

    if H_list[A] > H_list[B]:
        taller_set.add(A)
        smaller_set.add(B)
    else:
        taller_set.add(B)
        smaller_set.add(A)

    all_tower_with_roads = all_tower_with_roads | set([A, B])

answer_set = (all_tower_with_roads - (taller_set | smaller_set)) | (taller_set - smaller_set)
print(len(answer_set))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
x = []
for j in range(m):
    a = list(map(int, input().split()))
    s = a[0] - 1
    t = a[1] - 1
    if h[s] < h[t]:
        x.append(s)
    elif h[s] > h[t]:
        x.append(t)
    else:
        continue
print(len(set(x)))

Submission status: Wrong Answer

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

is_min = [0 for _ in range(N)]
for i in range(M):
    if root[i][0] > root[i][1]:
        is_min[root[i][1]] = 1

    elif root[i][0] == root[i][1]:
        is_min[root[i][0]] = 1
        is_min[root[i][1]] = 1

    else:
        is_min[root[i][0]] = 1

print(N - sum(is_min))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h = list(map(int,input().split()))
a = [list(map(int,input().split())) for j in range(m)]
# print("h:",h)
# print("a",a)
can_go = [[] for i in range(n)]
# print(can_go)
for i in a:
    # print(i)
    can_go[i[0]-1].append(i[1])
    can_go[i[1]-1].append(i[0])
# print(can_go)
b = 0
ans=0
for i,j in enumerate(can_go):
    # for j in can_go:
    b= 0

    for k in j:
        print( h[k-1]-h[i])
        if h[k-1]>=h[i]:
            b=1
            # print("break")
            break
    if b==1:
        b=0
    else:
        ans+=1
print(ans)

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())
  if h[a-1]=='x' or h[b-1]=='x':
    None
  elif h[a-1]>h[b-1]:
    h[b-1]='x'
  elif h[a-1]<h[b-1]:
    h[a-1]='x'
  else:
    h[a-1]='x'
    h[b-1]='x'
print(n-h.count('x'))

Submission status: Wrong Answer

Solution code:
from itertools import chain

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

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

count = 0

for i in range(1, n+1):
    f = {i}
    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =set(chain.from_iterable(c)) -f
    #print(d)

    for k in d:
        e.append(H[k-1])



    if len(e)==0:
        count += 1
        #print('Yes')

        continue
    elif max(e) < H[i-1]:
        print(i, H[i - 1], max(e))
        count += 1
        #print('Yes')
    else:
        pass

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import chain

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

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

count = 0

for i in range(1, n+1):

    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =set(chain.from_iterable(c))
    #print(d)

    for k in d:
        e.append(H[k-1])



    if len(e)==0:
        count += 1
        #print('Yes')

        continue
    elif max(e) == H[i-1]:
        #print(i, H[i - 1], max(e))
        count += 1
        #print('Yes')
    else:
        pass

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import chain

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

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

count = 0

for i in range(1, n+1):

    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =list(chain.from_iterable(c))

    for k in d:
        e.append(H[k-1])

    if len(e)==0:
        count += 1

        continue
    elif max(e) == H[i-1]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import chain

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

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

count = 0

for i in range(1, n+1):

    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =list(chain.from_iterable(c))

    for k in d:
        e.append(H[k-1])

    if len(e)==0:

        continue
    elif max(e) == H[i-1]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
inp = stdin.readline
out = stdout.write
n,m = map(int,inp().split())
h = [int(u) for u in inp().split()]
adj = [[] for _ in range(n)]
for i in range(m):
    u,v = map(int,inp().split())
    u -= 1
    v -= 1
    adj[u].append(v)
    adj[v].append(u)
marked = [False for _ in range(n)]
cnt = 0
for u in range(n):
    #if marked[u]: continue
    good = True
    for v in adj[u]:
        if h[u] < h[v]:
            good = False
            break
        else: marked[v] = True
    if good: cnt += 1
out(str(cnt))

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
inp = stdin.readline
out = stdout.write
n,m = map(int,inp().split())
h = [int(u) for u in inp().split()]
adj = [[] for _ in range(n)]
for i in range(m):
    u,v = map(int,inp().split())
    u -= 1
    v -= 1
    adj[u].append(v)
    adj[v].append(u)
marked = [False for _ in range(n)]
cnt = 0
for u in range(n):
    if marked[u]: continue
    good = True
    for v in adj[u]:
        if h[u] < h[v]:
            good = False
            break
        else: marked[v] = True
    if good: cnt += 1
out(str(cnt))

Submission status: Wrong Answer

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

H = [int(N) for N in input().split()]
check = []

for i in range(M):
    A = [int(a) for a in input().split()]
    check.append(max(H[A[0]-1], H[A[1]-1]))

ans = collections.Counter(check)
print(len(ans))

Submission status: Wrong Answer

Solution code:
import collections
N, M = map(int, input().split())
# print(N, M)


H = [int(N) for N in input().split()]
# print(H)
check = []

for i in range(M):
    A = [int(a) for a in input().split()]
    check.append(max(A))

ans = collections.Counter(check)
print(len(ans))

Submission status: Wrong Answer

Solution code:
(n, m), h, *r = [[*map(int, i.split())] for i in open(0)]
g =[] + h

for i in r:
    g[i[0]-1] *= h[i[0]-1] > h[i[1]-1]
    g[i[1]-1] *= h[i[1]-1] > h[i[0]-1]
print(len(set(g) - {0}))

Submission status: Wrong Answer

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

x = [set() for _ in range(n)]
for a, b in ab:
    x[a-1].add(b-1)
    x[b-1].add(a-1)
print(x)    
ans = 0
for i, xx in enumerate(x):
    for xxx in xx:
        if h[i] <= h[xxx]:
            break
    else:
        ans += 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
H = [0] + list(map(int, readline().split()))
A = [0]*(N+1)

m = map(int, read().split())
for a,b in zip(m,m):
	for _ in range(2):
		A[a] = max(A[a], H[b])
		a,b = b,a

print(sum(x>y for x,y in zip(A, H)))

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m = map(int,input().split())
h = np.array(list(map(int,input().split())))

#base = np.zeros(n)
#seen = np.zeros((n,n))

#for i in range(m):
#  a,b = map(int,input().split())
#  seen[a-1,b-1] = 1
#  seen[b-1,a-1] = 1
  
ans = 0
#for i in range(n):
#  temp = np.multiply(seen[i],h)
#  temp_1 = np.max(temp)
#  if (h[i] > temp_1) and (temp_1 != 0):
#    ans += 1
#  elif temp_1 == 0:
#    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().rstrip().split())
hl = [int(v) for v in input().rstrip().split()]
ml = hl.copy()
for i in range(m):
    a, b = map(int, input().rstrip().split())
    a -= 1
    b -= 1
    ml[a] = max(ml[a], hl[b])
    ml[b] = max(ml[b], hl[a])

num = 0
for i in range(n):
    if hl[i] == ml[i]:
        num += 1

print(num)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().rstrip().split())
hl = [int(v) for v in input().rstrip().split()]
ml = hl.copy()
for i in range(m):
    a, b = map(int, input().rstrip().split())
    a -= 1
    b -= 1
    ml[a] = max(ml[a], ml[b])
    ml[b] = max(ml[a], ml[b])

num = 0
for i in range(n):
    if hl[i] == ml[i]:
        num += 1

print(num)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().rstrip().split())
hl = [int(v) for v in input().rstrip().split()]
ml = hl.copy()
for i in range(m):
    a, b = map(int, input().rstrip().split())
    a -= 1
    b -= 1
    ml[a] = max(hl[a], hl[b])
    ml[b] = max(hl[a], hl[b])

num = 0
for i in range(n):
    if hl[i] == ml[i]:
        num += 1

print(num)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split()) 
h = map(int, input().split()) 
h_list = list(h)
ab_list = []
for i in range(m):
    ab = list(map(int, input().split()))
    ab_list = ab_list + [ab]
d = 0
e = []
for i in range(n):
    f = []
    for j in range(m):
        c1 = ab_list[j][0]
        c2 = ab_list[j][1]
        if c1 == i+1:
            d = c2
            f.append(d)
        elif c2 == i+1:
            d = c1
            f.append(d)
    e.append(f)
ans = 0
for i in range(n):
    base = h_list[i]
    aaa = [base]
    for j in range(len(e[i])):
        com = h_list[e[i][j]-1]
        aaa.append(com)
    aaa_max = max(aaa)
    if aaa_max == aaa[0] and len(aaa) != 1:
        ans = ans + 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().rstrip().split())
hl = [int(v) for v in input().rstrip().split()]
goods = [ 1 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().rstrip().split())
    a -= 1
    b -= 1
    if hl[a] < hl[b]:
        hl[a] = hl[b]
        goods[a] = 0
    elif  hl[a] > hl[b]:
        hl[b] = hl[a]
        goods[b] = 0

print(sum(goods))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
h = list(map(int,input().split()))
n_ans=[1]*n

for i in range(m):
    a, b = map(int,input().split())
    if h[a-1] <= h[b-1] and n_ans[a-1] == 1:
        n_ans[a-1] = 0
    if h[a-1] <= h[a-1] and n_ans[b-1] == 1:
        n_ans[b-1] = 0
print(sum(n_ans))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H= [list(map(int,input().split())) ]
A= [list(map(int,input().split())) for i in range(M)]
AA=[]
import numpy as np

for u in range(0,M):
    for t in range(0,len(A[u])):
        AA.append(A[u][t])

def B(n):
    a=[A[n][1],A[n][0]]
    return a
for b in range(0,M):
    A.append(B(b))
A=np.array(A)


H=np.array(H)
def c(j):
    count=0
    for w in range(0,2*M):
        if A[w][0]==j and H[0][A[w][0]-1]>H[0][A[w][1]-1]:
            count=count+1
        else:
            count=count
    if count>1:
        if np.count_nonzero(A[:,:1][:,0]==j)==count:
            count=1
        else:
            count=0
    else:
        count=count
    return count

d=0
count_n=0
for r in range(1,N+1):
    if r not in A[:,:1][:,0]:
        count_n=count_n+1
    else:
        count_n=count_n
    d=d+c(r)
d=d+count_n
print(d)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
Ha = [0] * N
use = [0] * N
 
for i in range(M):
    x,y = map(int,input().split())
    use[x-1] = 1
    use[y-1] = 1
    if H[x-1] != H[y-1]:
        if Ha[x-1] == 1 and Ha[y-1] == 0:
            if H[x-1] < H[y-1]:
                Ha[x-1]=0
                Ha[y-1]=1
        elif Ha[x-1] == 0 and Ha[y-1] == 1:
            if H[x-1] > H[y-1]:
                Ha[x-1]=1
                Ha[y-1]=0
        else:    
            if H[x-1] > H[y-1]:
                Ha[x-1] = 1
                Ha[y-1] = 0
            else:
                Ha[x-1] = 0
                Ha[y-1] = 1
            
print(Ha.count(1) + use.count(0))

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
H = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(M)]
HH = [1 for _ in range(N)]
for ab in AB:
    if H[ab[0]-1] == H[ab[1]-1]:
        HH[ab[0]-1] = 0
        HH[ab[1]-1] = 0
    elif H[ab[0]-1] > H[ab[1]-1]:
        H[ab[1]-1] = H[ab[0]-1]
        HH[ab[1]-1] = 0
    else:
        H[ab[0]-1] = H[ab[1]-1]
        HH[ab[0]-1] = 0
print(sum(HH))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
Ha = [0] * N
use = [0] * N

for i in range(M):
    x,y = map(int,input().split())
    use[x-1] = 1
    use[y-1] = 1
    if Ha[x-1] == 1 and Ha[y-1] == 0:
        if H[x-1] < H[y-1]:
            Ha[x-1]=0
            Ha[y-1]=1
    elif Ha[x-1] == 0 and Ha[y-1] == 1:
        if H[x-1] > H[y-1]:
            Ha[x-1]=1
            Ha[y-1]=0
    else:    
        if H[x-1] > H[y-1]:
            Ha[x-1] = 1
            Ha[y-1] = 0
        else:
            Ha[x-1] = 0
            Ha[y-1] = 1
            
print(Ha.count(1) + use.count(0))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
Ha = [0] * N

for i in range(M):
    x,y = map(int,input().split())
    if Ha[x-1] == 1 and Ha[y-1] == 0:
        if H[x-1] < H[y-1]:
            Ha[x-1]=0
            Ha[y-1]=1
    elif Ha[x-1] == 0 and Ha[y-1] == 1:
        if H[x-1] > H[y-1]:
            Ha[x-1]=1
            Ha[y-1]=0
    else:    
        if H[x-1] > H[y-1]:
            Ha[x-1] = 1
            Ha[y-1] = 0
        else:
            Ha[x-1] = 0
            Ha[y-1] = 1
            
print(Ha.count(1))