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()))
t = [set() for _ in range(n)]

for _ in range(m):
    a,b = map(int, input().split())
    t[a-1].add(b-1)
    t[b-1].add(a-1)
ans = 0
for i in range(n):
    now_t = h[i]
    if t[i]:
        if all([now_t > tall for tall in t[i]]):
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
 
def resolve():
    N, M = map(int, input().split())
    a_list = []
    b_list = []
    h_list = list(map(int, input().split()))

    for i in range(M):
        a, b = map(int, input().split())
        a_list.append(a)
        b_list.append(b)

    not_good_oka_list = []

    for i in range(M):
        if h_list[a_list[i]-1] == h_list[b_list[i]-1]:
            not_good_oka_list.append(a_list[i]-1)
            not_good_oka_list.append(b_list[i]-1)
        elif h_list[a_list[i]-1] < h_list[b_list[i]-1]:
            not_good_oka_list.append(a_list[i]-1)
        else:
            not_good_oka_list.append(b_list[i]-1)

    print(len(set(not_good_oka_list)))

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for _ in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
import sys,bisect,math,collections
sys.setrecursionlimit(15000)

N,M = map(int,sys.stdin.readline().split())
h = list(map(int,sys.stdin.readline().split()))
g = list(range(N))
def find(x):
  while g[x] != x:
    x = g[x]
    g[x] = g[g[x]]
  return x
def union(s,t):
  sp = find(s)
  tp = find(t)
  if h[sp] == h[tp]:
    pass
  elif h[sp] < h[tp]:
    g[sp] = tp
  else:
    g[tp] = sp

for _ in range(M):
    a,b = list(map(int,sys.stdin.readline().split()))
    union(a-1,b-1)
print(len(collections.Counter(g)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

num = input().split(" ")

h = input().split(" ")

counter = [True for i in range(int(num[0]))]

for i in range(int(num[1])):
    ab = input().split(" ")
    if h[int(ab[0])-1] > h[int(ab[1])-1]:
        counter[int(ab[1])-1] = False
    elif h[int(ab[0])-1] < h[int(ab[1])-1]:
        counter[int(ab[0])-1] = False
    elif h[int(ab[0])-1] == h[int(ab[1])-1]:
        counter[int(ab[0])-1] = False
        counter[int(ab[1])-1] = False
        
print(counter.count(True))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, m  = map(int, input().split())
h  = list(map(int, input().split()))
ab  = [tuple(map(int, input().split())) for i in range(m)]
#
# c = collections.Counter()

ans = 0
tenbo = [0] * n
for (a, b) in ab:
    #print(tenbo)
    if h[a-1] > h[b-1]:
        if tenbo[a-1] != -1:
            tenbo[a-1] = 1
        tenbo[b-1] = -1
    if h[a-1] < h[b-1]:
        if tenbo[b-1] != -1:
            tenbo[b-1] = 1
        tenbo[a-1] = -1
    if h[a-1] == h[b-1]:
        if tenbo[a-1] != -1:
            tenbo[a-1] = 1
        if tenbo[b-1] != -1:
            tenbo[b-1] = 1

for tenbo_ in tenbo:
    if tenbo_ == 1:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = input().split(" ")
N, M = int(N), int(M)
H = [int(h) for h in input().split(" ")]
A = []
B = []
TF = [True] * N
for i in range(M):
    a, b = input().split(" ")
    a, b = int(a), int(b)
    if H[a-1] >= H[b-1]:
        if TF[b-1]:
            TF[b-1] = False
    elif H[b-1] >= H[a-1]:
        if TF[a-1]:
            TF[a-1] = False
            
print(sum(TF))

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
h=list(map(int, input().split()))
d={}
for i in range(1,n+1):
    d[i]=[]
for z in range(m):
    a,b=map(int, input().split())
    d[a].append(b)
    d[b].append(a)
ans=0
for i in range(1,n+1):
    val=0
    if len(d[i])!=0:
        for j in d[i]:
            if h[j-1]>h[i-1]:
                val=1
                break
        if val==0:
            ans=ans+1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n, m = map(int, input().split())
h = list(map(int, input().split()))
d = defaultdict(list)
num = 0
for _ in range(m):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)
for i, v in d.items():
    flag = False
    if not v:
        num += 1
        continue
    for j in v:
        if h[i-1] < h[j-1]:
            flag = True
    if not flag:
        num += 1
print(num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

d=dict(zip(k,H))

arr=[1]*N

for _ in range(M):
    a,b=map(int,input().split())
    if d[a]>d[b]:
        arr[b-1]=0
    elif d[a]<d[b]:
        arr[a-1]=0

print(sum(arr))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[]
c=0
for _ in range(m):
  a,b=map(int,input().split())
  if((a,b) not in l):
    if(h[a-1]>h[b-1]):
      c+=1
    elif(h[a-1]<h[b-1]):
      c+=1
  l.append((a,b))
print(c)

Submission status: Wrong Answer

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

high_list = list(map(int, input().split()))
check_list = [1]*N

for i in range(M):
  a_, b_ = map(int, input().split())
  if high_list[a_-1] < high_list[b_-1]:
    check_list[a_-1] = 0
  elif high_list[a_-1] > high_list[b_-1]:
    check_list[b_-1] = 0
  elif high_list[a_-1] == high_list[b_-1]:
    check_list[a_-1] = 0
    check_list[b_-1] = 0

print(len(check_list))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=input().split()
a=[]
b=[]
for i in range(0,m):
    ay,by=map(int,input().split())
    a.append(ay)
    b.append(by)


ans=[]

for i in range(0,m):
    
    if h[a[i]-1]>=h[b[i]-1]:
        ans.append(b[i]-1)
    if h[a[i]-1]<=h[b[i]-1]:
        ans.append(a[i]-1)


num=len(set(ans))
print(n-num)

Submission status: Wrong Answer

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

li = [0] + [-1] * N
for a, b in AB:
    ma = max(H[a-1], H[b-1])
    if ma==H[a-1]:
        li[b]=-4
    else:
        li[a]=-4

cnt=0

for i in range(N+1):
    if i==0:
        continue
    if li[i]==-4:
        cnt+=1
print(N-cnt)

Submission status: Wrong Answer

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

    temp = [True for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())

        if HN[A - 1] < HN[B - 1]:
            temp[A - 1] = False
        else:
            temp[B - 1] = False

    print(sum([1 for a in temp if a]))


main()

Submission status: Wrong Answer

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

ans =[1]*N

for i in range(M):
    a,b = map(int,input().split())
    a=a-1
    b=b-1

    if Peaks[a]>Peaks[b]:
        ans[a]=1
        ans[b]=0
    elif Peaks[a]<Peaks[b]:
        ans[a]=0
        ans[b]=1
    else:
        ans[a]=0
        ans[b]=0

print(sum(ans))

Submission status: Wrong Answer

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

A = [[] for i in range(N+1)]
for i in range(N+1):
    A[i].append(H[i-1])
for i in range(M):
    a,b = map(int, input().split())
    A[a].append(H[b-1])
    A[b].append(H[a-1])

ans = 0
for i in range(1,N+1):
    if max(A[i]) == A[i][0] :
        ans += 1

    if len(A[i]) != 1 and len(set(A[i])) == 1:
        ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
x, y = list(map(int, input().split()))

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

l = c.copy()

for _ in range(y):
    a, b = list(map(int, input().split()))
    if c[a-1] > c[b-1]:
        if b in l:
            l.remove(b)
    else:
        if a in l:
            l.remove(a)
print(len(l))

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])

H01 = [1]*N
for i in range(M):
    A,B = AB[i]
    if(H[A-1]<H[B-1]):
        H01[A-1] = 0
        H01[B-1] = 1
    else:
        H01[A-1] = 1
        H01[B-1] = 0
print(sum(H01))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
print(M)
Hs = list(map(int, input().split()))
i = 0
ABs = []
while True:
  if M <= i:
    break
  ABs.append(list(map(int, input().split())))
  i += 1
r = [0] * N
for x in ABs:
  if Hs[x[1]-1] < Hs[x[0]-1]:
    r[x[0]-1] += 1
  else:
    r[x[1]-1] += 1
print(r.count(0))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
Hn = list(map(int, input().split()))
abn = [list(map(int, input().split())) for _ in range(m)]
pool = [[h] for h in Hn]
for ab in abn:
    pool[ab[0]-1].append(Hn[ab[1]-1])
    pool[ab[1]-1].append(Hn[ab[0]-1])
ans = 0
for i in range(n):
    if len(pool[i]) == 1:
        ans += 1
    else:
        if max(pool[i]) == Hn[i] and max(pool[i]) > min(pool[i]):
            ans += 1
print(ans)

Submission status: Wrong Answer

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

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

for j in range(M):
  a, b = map(int,input().split())
  if(H[a-1] == H[b-1]):
    good[a-1] += 1
    good[b-1] += 1
    break
  elif(H[a-1] < H[b-1]):
    good[a-1] += 1
  else:
    good[b-1] += 1
count = 0
for i in range(N):
  if(good[i] == 0):
    count += 1
print(count)

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())
  if h[a-1] > h[b-1]:
    dic[str(a)] = h[a-1]
    if str(b) in dic:
      dic.pop(str(b))
  else:
    dic[str(b)] = h[b-1]
    if str(a) in dic:
      dic.pop(str(a))
    
print(len(dic))

Submission status: Wrong Answer

Solution code:
import collections
def main():

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

    d = dict()
    c = collections.defaultdict(int)
    s = set()
    for _ in range(M):
        A, B = map(int, input().split())
        if A > B: A, B = B, A
        c[(A, B)] += 1
        s.add(A)
        s.add(B)

    for v in c:
        if c[v] == 1:
            A, B = v[0], v[1]
            if A-1 not in d:
                d[A-1] = H[B-1]
            else:
                d[A-1] = max(H[B-1], d[A-1])

            if B-1 not in d:
                d[B-1] = H[A-1]
            else:
                d[B-1] = max(H[A-1], d[B-1])

    ans = 0
    for v in d:
        if H[v] > d[v]:
            ans += 1

    return ans + (N - len(s))

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy
n,m=map(int,input().split())
h=list(map(int,input().split()))
H = copy.deepcopy(h)
for _ in range(m):
    a,b=map(int,input().split())
    if H[b-1] - H[a-1] >= 0:
        h[a-1] = 0
    else:h[b-1] = 0
print(n-h.count(0))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
Hs = list(map(int,input().split()))
L = [[] for i in range(N)]
count = 0
for i in range(M):
    A, B = map(int,input().split())
    (L[A-1]).append(Hs[B-1])
    (L[B-1]).append(Hs[A-1])
for i in range(N):
    if not L[i]:
        count+=1
        continue
    if i+1 > max(L[i]):
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 7)


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))

    good = [True] * N

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

    print(good.count(True))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h_list = list(map(int,input().split()))
roads = []
for i in range(m):
    a,b = map(int,input().split())
    roads.append([a,b])
#print(roads)
terrace = [1] * n
for road in roads:
    if h_list[road[0]-1] > h_list[road[1]-1]:
        terrace[road[0]-1] = 1
        terrace[road[1]-1] = 0
    elif h_list[road[0]-1] == h_list[road[1]-1]:
        terrace[road[0]-1] = 0
        terrace[road[1]-1] = 0
    else:
        terrace[road[0]-1] = 0
        terrace[road[1]-1] = 1
print(terrace.count(1))

Submission status: Wrong Answer

Solution code:
import collections
N,M=map(int,input().split())    
H=list(map(int,input().split()))
ans=[1]*N
for _ in range(M):
    AB=list(map(int,input().split()))
    if H[AB[0]-1] < H[AB[1]-1]:
        ans[AB[0]-1]=0
    else:
        ans[AB[1]-1]=0
c=collections.Counter(ans)
print(c[1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, M = map(int, input().split())
H = list(map(int, input().split()))
lst = [list(map(int, input().split())) for _ in range(M)]

a = set()
b = set()
c = H
for i in lst:
    if H[i[0]-1] < H[i[1]-1]:
        a.add(i[1]-1)
        b.add(i[0]-1)
    else:
        a.add(i[0]-1)
        b.add(i[1]-1)

print(len(a))

Submission status: Wrong Answer

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

A = [[] for i in range(N+1)]
for i in range(N+1):
    A[i].append(H[i-1])
for i in range(M):
    a,b = map(int, input().split())
    A[a].append(H[b-1])
    A[b].append(H[a-1])

ans = 0
for i in range(1,N+1):
    print(A[i])
    if max(A[i]) == A[i][0] :
        ans += 1

    if len(A[i]) != 1 and len(set(A[i])) == 1:
        ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=input().split()
h_list = []
h_list = input().split(" ")
result =[]
count = 0
for i in range(int(n)):
    result.append(True)
for i in range(int(m)):
    temp1,temp2=input().split()
    if h_list[int(temp1)-1] < h_list[int(temp2)-1]:
        result[int(temp1)-1] = False
    else:
        result[int(temp2)-1] = False
for i in range(int(n)):
    if(result[i]==True):
        count += 1
    else:
        pass
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n,m=map(int,input().split())
    h=list(map(int,input().split()))
    dic={}
    for i in range(m):
        a,b=map(int,input().split())
        dic.setdefault(a,[]).append(b)
        dic.setdefault(b,[]).append(a)
    ans=0
    for i in h:
        tmp=i
        f=True
        if i in dic:
            for j in dic[i]:
                if tmp<=j:
                   f=False
        if f: ans+=1
    print(ans)

if __name__ =='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = []
b = []
cnt = 0
while True:
  try:
    ta,tb = map(int,input().split())
    a.append(ta)
    b.append(tb)
  except:
    break

highest = h.index(max(h))+1

for i in range(1,m+1):
  if i not in a and i not in b:
    cnt +=1
  if a[i-1]==highest or b[i-1]==highest:
    cnt +=1
print(cnt)

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)]
d=[ [] for i in range(n+1)]
for i in range(m):
  #a=ab[i][0]
  #b=ab[i][1]
  d[ab[i][0]].append(h[ab[i][1]-1])
  d[ab[i][1]].append(h[ab[i][0]-1])
count=0
for i in range(0,len(d)-1):
  if len(d[i+1])==0:
    count+=1
  elif h[i]<max(d[i+1]):
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = [None] + [int(x) for x in input().split()]

res = [0] + ([1] * n)

for _ in range(m):
    a, b = map(int, input().split())
    if h[a] >= h[b]:
        res[b] = 0
    elif h[a] <= h[b]:
        res[a] = 0

print(sum(res))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
input()
outs = [1] * N
for _ in range(K):
    a,b = map(int,input().split())
    if outs[a-1] == 0 or outs[b-1] == 0:
        continue
    else:
        outs[b-1] = 0
print(sum(outs))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
arr=[int(i) for i in input().split()]
hashmap=dict()
count=dict()
for key in range(1,n+1):
  hashmap[key]=arr[key-1]
  count[key]=0

result=0
for i in range(m):
  a,b=map(int,input().split())
  if hashmap[a]<hashmap[b]:
    count[a]+=1
  else:
    count[b]+=1  

for i in range(1,n+1):
  if count[i]==0:
    result+=1
    
print(result)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
ab = [[0]*N for j in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    ab[a][b] += 1
    ab[b][a] += 1
cnt=0
for i in range(N):
    x = ab[i][:i]
    if sum(x)==0:
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0, None)
alone = list(map(int, range(1, n+1)))
nice = [0]*n
for _ in range(m):
    a, b = map(int, input().split())
    if a in alone:
        alone.remove(a)
    if b in alone:
        alone.remove(b)
    
    if h[a] > h[b]:
        nice[a-1] = 1
    elif h[a] < h[b]:
        nice[b-1] = 1

print(nice.count(1)+len(alone))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
table = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    table[a-1].append(b-1)
    table[b-1].append(a-1)
count = 0
for i in range(len(table)):
    for j in range(len(table[i])):
        if h[table[i][j]] <= h[i]:
            break
    else:
        count += 1
    if table[i] == []:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# C問題
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for i in range(m):
    a[i], b[i] = map(int, input().split())
answer = [i+1 for i in range(n)]
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        index = a[i]-1
        if index in answer:
            answer.remove(index)
    else:
        index = b[i]-1
        if index in answer:
            answer.remove(index)
print(len(answer))

Submission status: Wrong Answer

Solution code:
import itertools
 
def resolve():
    N, M = map(int, input().split())
    a_list = []
    b_list = []
    h_list = list(map(int, input().split()))

    for i in range(M):
        a, b = map(int, input().split())
        a_list.append(a)
        b_list.append(b)

    not_good_oka_list = []

    for i in range(M):
        if h_list[a_list[i]-1] < h_list[b_list[i]-1]:
            not_good_oka_list.append(a_list[i]-1)
        else:
            not_good_oka_list.append(b_list[i]-1)

    print(len(set(not_good_oka_list)))

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
ll=[]
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]<h[b-1]:
        lose=[a]
    elif h[a-1]>h[b-1]:
        lose=[b]
    else:
        lose=[a,b]
    ll += lose
print(ll)
import collections
c=collections.Counter(ll)
print(n-len(c))

Submission status: Wrong Answer

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

bad_view = set()

for road in roads:
    a = h_list[road[0]-1]
    b = h_list[road[1]-1]
    tmp = min(a,b)
    bad_view.add(tmp)

print(n-len(bad_view))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst):
        self.graph[src].append((dst))

    def get_nodes(self):
        return self.graph.keys()


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(M)]

    g1 = Graph()
    for ab in AB:
        if H[ab[0]-1] >= H[ab[1]-1]:
            g1.add_edge(ab[1], ab[0])
        elif H[ab[0]-1] <= H[ab[1]-1]:
            g1.add_edge(ab[0], ab[1])

    print(N-len(g1))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
nm = input('')
n=int(nm.split(' ')[0])
m=int(nm.split(' ')[1])
hs = input('').split(' ')

abmap = {}
for i in range(m):
    ab = input('')
    a = int(ab.split(' ')[0])
    b = int(ab.split(' ')[1])
    if a in abmap.keys():
        abmap[a].append(b)
    else:
        abmap[a] = [b]
    if b in abmap.keys():
        abmap[b].append(a)
    else:
        abmap[b] = [a]

ytb_cnt=0
for a,b in abmap.items():
    ah = hs[a-1]
    ytb = 1
    for bn in b:
        bh = hs[bn-1]
#        print("{}[{}]->{}[{}]".format(a,ah,b,bh))
        if int(ah) <= int(bh):
            ytb=0
    if ytb == 1:
        ytb_cnt+=1
print(ytb_cnt)

Submission status: Wrong Answer

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

a = [0] * m
b = [0] * m
d = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1
    if h[a[i]] < h[b[i]]:
        d[a[i]][b[i]] = 1
    else:
        d[b[i]][a[i]] = 1

ans = 0

for i in range(n):
    if sum(d[i]) == 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#C
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
# print(ab)
t=[0]*n
for i in ab:
    if h[i[0] - 1] > h[i[1] - 1]:
        t[i[1] - 1] = -1
    elif h[i[0] - 1] < h[i[1] - 1]:
        t[i[0] - 1] = -1
# print(t)
count=0
for i in t:
    if i == 0:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
H = [int(a) for a in input().split()]
ans= [1] * n
for i in range(m):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        ans[b-1] = 0
#     elif H[a-1] == H[b-1]:
#         ans[a-1] = 0
#         ans[b-1] = 0
    elif H[a-1] < H[b-1]:
        ans[a-1] = 0
print(sum(ans))

Submission status: Wrong Answer

Solution code:
# input
inp_ls = input().split(" ")
n,m = [int(e) for e in inp_ls[:2]]
h_ls = [int(e) for e in input().split(" ")[:n]]

# calc
obs_dic = {i+1: [] for i in range(n)}
for i in range(m):
	a,b = [int(e) for e in input().split(" ")[:2]]
	obs_dic[a].append(b)
	obs_dic[b].append(a)

# unique
for o0 in obs_dic:
	o0_ls = list(set(obs_dic[o0]))
	obs_dic[o0] = o0_ls
# print(obs_dic)

cnt = 0
for o0 in obs_dic:
	o0_h = h_ls[o0-1]
	if len(obs_dic[o0]) < 1:
		flag = False
		continue
	flag = True
	for o1 in obs_dic[o0]:
		o1_h = h_ls[o1-1]
		if o0_h < o1_h: flag = False
	# print(o0, flag)
	if flag is True: cnt += 1

# result
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = [0] * m
b = [0] * m
for i in range(m):
    a[i],b[i] = map(int,input().split())
g = [0] * n
for i in range(m):
    if h[a[i]-1] < h[b[i]-1]:
        g[a[i]-1] = 1
    else:
        g[b[i]-1] = 1
c = 0
for i in range(n):
    if g[i] == 0:
        c += 1

print(c)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
heights=list(map(int,input().split()))
heights_w=sorted([(h,i+1) for i,h in enumerate(heights)])
cons={i+1:set() for i in range(n)}
for _ in range(m):
  a,b=map(int,input().split())
  cons[a].add(b)
  cons[b].add(a)

watched=set()
res=0
for h,i in heights_w:
  if i in watched:
    continue
  watched.add(i)
  flg=True
  for con in cons[i]:
    flg=(flg and h<=heights[con-1])
    watched.add(con)
  if flg:
    res+=1
print(res)

Submission status: Wrong Answer

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

for i in range(M):
    A[i],B[i]=map(int,input().split())
    max_ab=max(A[i],B[i])
    flag_ch[max_ab-1]=1

cnt=0
for tmp in flag_ch:
    if(tmp==1):
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

gooddict={i:1 for i in range(1,n+1)}

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

count=0
for i in range(1,n+1):
  if gooddict[i]==1:
    count+=1
print(count)
print(gooddict)

Submission status: Wrong Answer

Solution code:
import sys
import math
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import itertools
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
H = LIST()

L = []

for i in range(M):
    a, b = MAP()
    L.append([a, b])

flag = [1] * N

for i, j in L:
    if H[i-1] < H[j-1]:
        flag[i-1] = 0
    elif H[i-1] > H[j-1]:
        flag[j-1] = 0
    else:
        flag[i-1] = 0
        flag[j-1] = 0

print(flag.count(1))

Submission status: Wrong Answer

Solution code:
class UnionFind:
    def __init__(self, n):
        self.root = list(range(n))
        self.size = [1] * (n)
        self.maxh = [0] * (n)
    def find_root(self, x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x

    def merge(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        sx,sy = self.size[x],self.size[y]
        if sx < sy:
            self.root[x] = y
            self.size[y] += sx
            self.maxh[y] = max(h[x], h[y])
        else:
            self.root[y] = x
            self.size[x] += sy
            self.maxh[y] = max(h[x], h[y])

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

uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    uf.merge(a-1, b-1)

#print(h)
#print(uf.root)
#print(uf.maxh)
maxh = [0] * n
for i in range(n):
    maxh[uf.find_root(i)] = max(maxh[uf.find_root(i)], h[i])
    #print(i, uf.find_root(i), uf.maxh[uf.find_root(i)], h[i])
#print(maxh)
ans = 0
for i in range(n):
    if maxh[uf.find_root(i)] == h[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
list1=list(map(int,input().strip().split()))[:2]
n,m=list1[0],list1[1]
arr=list(map(int,input().strip().split()))[:n]
dict1={}
for i in range(m):
	l=list(map(int,input().strip().split()))[:2]
	key,val=l[0],l[1]
	if key in dict1:
		dict1[key].append(val)
	else:
		dict1[key]=[]
		dict1[key].append(val)
	if val in dict1:
		dict1[val].append(key)
	else:
		dict1[val]=[]
		dict1[val].append(key)
count=0
for i in arr:
	flag=0
	if i in dict1:
		for j in dict1[i]:
			if(i <= j):
				flag=1
				break
	if(flag==0):
		count+=1
print(count)

Submission status: Wrong Answer

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

count = N
for i in range(M):
    a, b = map(int, input().split())
    if H[a - 1] <= H[b - 1] and flag[a - 1] is False:
        flag[a - 1] = True
        count -= 1
    elif H[a - 1] >= H[b - 1] and flag[b - 1] is False:
        flag[b - 1] = True
        count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H_list = [int(_) for _ in input().split()]
A_list = []
B_list = []
for i in range(M):
    a, b = map(int, input().split())
    A_list.append(a)
    B_list.append(b)

N_list = [i+1 for i in range(N)]
good = []

for i in N_list:
    this_h = H_list[i-1]
    other_h = 0
    for j in range(M):
        tmp1 = 0
        tmp2 = 0
        if A_list[j] == i:
            tmp1 = H_list[B_list[j]-1]
        elif B_list[j] == i:
            tmp2 = H_list[A_list[j]-1]
        if other_h < max(tmp1, tmp2):
                other_h = max(tmp1, tmp2)
    if this_h > other_h:
        good.append(i)

print(good)
print(len(good))