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:
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
 
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

_, e = I()
hs = Is()

obs = sorted([(i, h) for i, h in enumerate(hs, 1)], key=lambda x:x[1], reverse=True)
seen = D(bool)

roads = D(set)
for _ in range(e):
  a, b = I()
  roads[a].add(b)
  roads[b].add(a)
  
ans = 0
for ob in obs:
  if not seen[ob[0]]:
    if all(ob[0] > hs[r-1] for r in roads[ob[0]]):
      ans += 1
    seen[ob[0]] = True
    for r in roads[ob[0]]:
      seen[r] = True
      
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
ab = []
w = []
for i in range(m):
    a,b = map(int, input().split())
    ab.append((a,b))
    ab.append((b,a))
    w.append(a)
    w.append(b)
ab = list(set(ab))
ab.sort()
num = 0
for j in range(1,n+1):
    s = 0
    t = 0
    for l in ab:      
        if l[0] == j and h[l[1]-1] < h[l[0]-1]:
            t += 1
    if 1 <= t:
        num += 1
    if j not in w:
        num += 1
print(num)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
rute = [[] for _ in range(N+1)]
#N番目の展望台が現れたかを保持
ap = [False]*(N+1)

sortedID = sorted(range(1, N+1), key=lambda x: -H[x-1])

for m in range(M):
    a, b = map(int, input().split())
    if H[a-1] >= H[b-1]: 
        AB.append((a, b))
    else:
        AB.append((b, a))

AB = sorted(AB, key=  lambda a: a[0])
beforeB = 0
beforeA = 0
for a, b in AB:
    if beforeA != a or beforeB != b:
        rute[a].append(b)
    beforeB = b
    beforeA = a
#print(sortedID)
#print(rute)
count = 0

for iD in sortedID:
    #print(ap)
    if ap[iD] != True:
        ap[iD] = True
        #print('appear: {}'.format(iD))
        count += 1
    for to in rute[iD]:
        if ap[to] == False:
            ap[to] = True
print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
rute = [[] for _ in range(N+1)]
#N番目の展望台が現れたかを保持
ap = [False]*(N+1)

sortedID = sorted(range(1, N+1), key=lambda x: -H[x-1])

for m in range(M):
    a, b = map(int, input().split())
    if H[a-1] >= H[b-1]: 
        AB.append((a, b))
    else:
        AB.append((b, a))

AB = sorted(AB, key=  lambda a: a[0])
beforeB = 0
beforeA = 0
for a, b in AB:
    if beforeA != a or beforeB != b:
        rute[a].append(b)
    beforeB = b
    beforeA = a
#print(sortedID)
#print(rute)
count = 0
    
for iD in sortedID:
    if ap[iD] != True:
        ap[iD] = True
        count += 1
        dfs = deque()
        dfs.extend(rute[iD])
        #print(dfs)
        while len(dfs) > 0:
            to = dfs.pop()
            #print(to)
            if ap[to] == False:
                ap[to] = True
                dfs.extend(rute[to])
print(count)

Submission status: Wrong Answer

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

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

road_list = []

for i in range(M):
    road = list(map(int, input().split()))
    road_list.append(road)

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

for i in range(M):
    #print(i, road_list[i][0]-1)
    if H_list[road_list[i][0]-1] > H_list[road_list[i][1]-1] and ans_list[road_list[i][0]-1] != -1:
        ans_list[road_list[i][0]-1] = 0
        ans_list[road_list[i][1]-1] = -1
    elif H_list[road_list[i][0]-1] < H_list[road_list[i][1]-1] and ans_list[road_list[i][1]-1] != -1:
        ans_list[road_list[i][1]-1] = 0
        ans_list[road_list[i][0]-1] = -1
    elif H_list[road_list[i][0]-1] == H_list[road_list[i][1]-1]:
        ans_list[road_list[i][1]-1] = -1
        ans_list[road_list[i][0]-1] = -1
        

#print(ans_list)    
print(ans_list.count(0))

Submission status: Wrong Answer

Solution code:
n,m=list(map(int, input("").split()))
h=list(map(int, input("").split()))
a=[]
b=[]
for i in range(m):
    ai,bi=list(map(int, input("").split()))
    a.append(ai)
    b.append(bi)
ma=0
out=0
for i in range(n):
    ma=h[i]
    q=h[i]
    for j in range(m):
        if i==a[j]-1 or i==b[j]-1:
            if i==a[j]-1:
                if h[b[j]-1] >= ma:
                    ma=0
            else:
                if h[a[j]-1] >= ma:
                    ma=0
    print(ma,q)
    if ma==q:  
        out+=1
print(out)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
bad = []
for i in range(M):
    A,B = map(int,input().split())
    if H[A-1] > H[B-1]:
        bad.append(H[B-1])
    elif H[A-1] < H[B-1]:
        bad.append(H[A-1])
    else:
        bad.append(H[A-1])
        bad.append(H[B-1])
print(N-len(set(bad)))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
good = []
for i in range(M):
    A,B = map(int,input().split())
    if H[A-1] > H[B-1]:
        good.append(H[A-1])
        if H[B-1] in good:
            good.remove(H[B-1])
    elif H[A-1] < H[B-1]:
        good.append(H[B-1])
        if H[A-1] in good:
            good.remove(H[A-1])
print(len(set(good)))

Submission status: Wrong Answer

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

h_sort = []

for i,hight in enumerate(h):
    h_sort.append((i+1,hight))

h_sort.sort(key=lambda x:x[1],reverse=True)

check = [1]*(len(h_sort))

for tower in h_sort:
    id = tower[0]
    
    while id in a:
        index = a.index(id)
        low_id = b[index]
        check[low_id-1] = 0
        a[index],b[index] = 0,0
    
    while id in b:
        index = b.index(id)
        low_id = a[index]
        check[low_id-1] = 0
        a[index],b[index] = 0,0
    
print(check.count(1))

Submission status: Wrong Answer

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

t = [n + 1]*n
for i in range(m):
	a, b = input().split()
	a = int(a)
	b = int(b)
	if h[a-1] >= h[b-1]:
		t[a-1] = a-1
	elif h[b-1] >=h[a-1]:
		t[b-1] = b-1

print(t.count(n+1))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
G={i+1 for i in range(N)}
for _ in range(M):
  a,b=map(int,input().split())
  if H[a-1]>H[b-1]:
    H[b-1]=H[a-1]
    G-={b}
  elif H[b-1]>H[a-1]:
    H[a-1]=H[b-1]
    G-={a}
print(len(G))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
G={i+1 for i in range(N)}
for _ in range(M):
  a,b=map(int,input().split())
  if H[a-1]>H[b-1]:
    H[b-1]=H[a-1]
    G-={b}
  elif H[b-1]>H[a-1]:
    H[a-1]=H[b-1]
    G-={a}
  else:
    G-={a,b}
print(len(G))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split()) 
hlist = list(map(int, input().split())) 
num = [0]*n
for j in range(m): #各道
    a, b = map(int, input().split())
    if hlist[a-1] >= hlist[b-1]:
        num[b-1] = 1
    elif hlist[a-1] <= hlist[b-1]:
        num[a-1] = 1
print(num.count(0))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
x,c=[],[]
for i in range(m):
    a,b=map(int,input().split())
    c.append(a)
    c.append(b)
    if h[a-1]<h[b-1]:
        x.append(h[b-1])
    elif h[b-1]<h[a-1]:
        x.append(h[a-1])

print(n-len(set(c))+len(set(x)))

Submission status: Wrong Answer

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

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

rank_hlist = sorted(hlist)
rank_dict = dict()
for i in range(n):
    rank_dict[rank_hlist[i]] = i

ab_list = []
for i in range(m):
    a, b = map(int,input().split())
    if rank_dict[hlist[a-1]] < rank_dict[hlist[b-1]]:
        a,b = b,a
    ab_list.append([a,b])

good_n = [1]*n

ab_list.sort(key=lambda x:x[0], reverse=True)

for i in range(m):
    ab = ab_list[i]
    if rank_dict[hlist[ab[0]-1]] >= rank_dict[hlist[ab[1]-1]]:
        good_n[ab[1]-1] = 0

print(good_n.count(1))

Submission status: Wrong Answer

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

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

rank_hlist = sorted(hlist)
rank_dict = dict()
for i in range(n):
    rank_dict[rank_hlist[i]] = i
    
ab_list = []
for i in range(m):
    a, b = map(int,input().split())
    if rank_dict[hlist[a-1]] < rank_dict[hlist[b-1]]:
        a,b = b,a
    ab_list.append([a,b])

good_n = [1]*n

ab_list.sort(key=lambda x:x[0], reverse=True)

for i in range(m):
    ab = ab_list[i]
    good_n[ab[1]-1] = 0

print(good_n.count(1))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int,input().split()))
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)  
print(graph)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[0]*N
for i in range(M):
    A,B=map(int,input().split())
    L[A-1]=max(L[A-1],L[B-1],H[A-1],H[B-1])
    L[B-1]=L[A-1]
ans=0
for j in range(N):
    if H[j]==L[j] or L[j]==0:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
height_list = list(map(int, input().split()))
roads = [list(map(int, input().split())) for _ in range(m)]
count = 0
neibors_list =[]
for i in range(n):
    neibor_highest =0
    if i in neibors_list:
        continue
    neibors_list_new=[]
    for road in roads:
        if i == road[0]:
            neibors_list_new.append(road[1])
            if neibor_highest <= height_list[road[1]-1]:
                neibor_highest= height_list[road[1]-1]
        elif i == road[1]:
            neibors_list_new.append(road[0])
            if neibor_highest <= height_list[road[0]-1]:
                neibor_highest= height_list[road[0]-1]
    #print(i, neibor_highest)
    if neibor_highest <= height_list[i]:
        count +=1
        neibors_list.append(i)
        neibors_list = neibors_list+ neibors_list_new
        
print(count)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
height_list = list(map(int, input().split()))
roads = [list(map(int, input().split())) for _ in range(m)]
count = 0
for i in range(n):
    neibor_highest =0
    for i_road, road in enumerate(roads):
        if i == road[0]:
            if neibor_highest <= height_list[road[1]-1]:
                neibor_highest= height_list[road[1]-1]
        elif i == road[1]:
            if neibor_highest <= height_list[road[0]-1]:
                neibor_highest= height_list[road[0]-1]
    #print(i, neibor_highest)
    if neibor_highest <= height_list[i]:
        count +=1
        
print(count)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
height_list = list(map(int, input().split()))
roads = [list(map(int, input().split())) for _ in range(m)]
count = 0
for i in range(n):
    neibor_list =[]
    for i_road, road in enumerate(roads):
        if i == road[0]:
            neibor_list.append(road[1])
        elif i == road[1]:
            neibor_list.append(road[0])
    #print(i, neibor_list)
    if neibor_list ==[]:
        count +=1
    else:
        neibor_high = [height_list[l-1] for l in neibor_list]
        if max(neibor_high) < height_list[i]:
            count +=1
        
print(count)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
height_list = list(map(int, input().split()))
roads = [list(map(int, input().split())) for _ in range(m)]
count = 0
for i in range(n):
    neibor_list =[]
    for i_road, road in enumerate(roads):
        if i == road[0]:
            neibor_list.append(road[1])
        elif i == road[1]:
            neibor_list.append(road[0])
    print(i, neibor_list)
    if neibor_list ==[]:
        count +=1
    else:
        neibor_high = [height_list[l-1] for l in neibor_list]
        if max(neibor_high) < height_list[i]:
            count +=1
        
print(count)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
h = list(map(int, input().split()))
nice = list(1 for i in range(n))
def chk_nice(x,y): 
    global nice
    nice[x] = (h[x] > h[y])
for i in range(m):
    a,b = list(map(int, input().split()))
    chk_nice(a-1, b-1)
    chk_nice(b-1, a-1)
print(sum(nice))

Submission status: Wrong Answer

Solution code:
def mapt(fn, *args):
    return tuple(map(fn, *args))
  
n, m = mapt(int, input().split(" "))
h = mapt(int, input().split(" "))
a = [mapt(int, input().split(" ")) for i in range(m)]


def first_func(row, i):
    if not row: return 1
    if i == row[0][0]:pass
    else: row = [(b, a) for a, b in row]
    result = [h[a-1] - h[b-1] > 0 for a, b in row]

    return all(result)


r = 0
for i in range(1, n+1):
    temp = []
    for row in a:
        if i in row:
            temp.append(row)
    r += first_func(temp, i)

print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
ppp=[]
for _ in range(m):
  r=list(map(int, input().split()))
  ppp.append(r)
c=0
p = list(map(list, set(map(tuple, ppp))))
for i in range(1,n+1):
  rr=[]
  rrr=[]
  for road in p:
 
    if road[0] == i:
      rr.append(road[1])

 
  if rr!=[]:
    for rra in rr:
      rrr.append(h[rra-1])

  if rrr!=[]:

    if h[i-1] > max(rrr):
      c+=1
  else:
    c+=1
print(c)

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


point = [0]*n
app = [0]*n
cnt = []

for i in ab:
    app[i[0]-1] += 1
    app[i[1]-1] += 1
    if h[i[0]-1] > h[i[1]-1]:
        point[i[0]-1] += 1
    elif h[i[0]-1] < h[i[1]-1]:
        point[i[1]-1] += 1
for i in range(n):
    if app[i] == point[i]:
        cnt.append(i+1)
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix_2
# CreatedDate:  2020-08-08 01:59:29 +0900
# LastModified: 2020-08-08 02:09:05 +0900
#


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


def main():
    n, m  = map(int, input().split())
    h = [0] + list(map(int, input().split()))
    path = [[] for _ in range(n+1)]
    for _ in range(m):
        a, b = map(int, input().split())
        path[a].append(h[b])
        path[b].append(h[a])
    ans = 0
    for index in range(1, n+1):
        if path[index] and h[index] > max(path[index]):
            ans += 1
        elif not path[index]:
            pass

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

#print(N,M,H)

bad=set()
for ln in sys.stdin:
    A,B=map(int,ln.split())
    x,y=H[A-1],H[B-1]
    if x>y:
        bad.add(y)
    elif x<y:
        bad.add(x)
    else:
        bad.add(x)
        bad.add(y)

print(N-len(bad))

Submission status: Wrong Answer

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

print(N,M,H)

bad=set()
for ln in sys.stdin:
    A,B=map(int,ln.split())
    x,y=H[A-1],H[B-1]
    if x>y:
        bad.add(y)
    elif x<y:
        bad.add(x)
    else:
        bad.add(x)
        bad.add(y)

print(N-len(bad))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

H=[]
H=list(map(int,input().split()))
C=[]
for i in range(n):
    C.append(1)

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

print( C.count(1))

Submission status: Wrong Answer

Solution code:
class tower:
    def __init__(self, H):
        self.H = H
        self.neighbors = []
        self.checked = False
    def add_path(self, a):
        self.neighbors.append(a)
N, M = [int(i) for i in input().split()]
Hs = [int(i) for i in input().split()]
T = {}
for i in range(N):
    T[i+1] = tower(Hs[i])
for i in range(M):
    A, B = [int(i) for i in input().split()]
    T[A].add_path(B)
    T[B].add_path(A)
items_sorted = sorted(T.items(), key = lambda x : x[1].H, reverse=1)
counter = 0
for each in items_sorted:
    i = each[0]
    t = each[1]
    if t.checked:
        continue
    else:
        t.checked = True
        for a in t.neighbors:
            flag = True
            T[a].checked = True
            if t.H <= T[a].H:
                flag = False

        if flag:
            print(i, flag)
            counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
class tower:
    def __init__(self, H):
        self.H = H
        self.neighbors = []
        self.checked = False
    def add_path(self, a):
        self.neighbors.append(a)
N, M = [int(i) for i in input().split()]
Hs = [int(i) for i in input().split()]
T = {}
for i in range(N):
    T[i+1] = tower(Hs[i])
for i in range(M):
    A, B = [int(i) for i in input().split()]
    T[A].add_path(B)
    T[B].add_path(A)
items_sorted = sorted(T.items(), key = lambda x : x[1].H, reverse=1)
counter = 0
for each in items_sorted:
    i = each[0]
    t = each[1]
    if t.checked:
        continue
    else:
        t.checked = True
        for a in t.neighbors:
            flag = True
            if t.H <= T[a].H:
                flag = False
        if flag:
            counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
word = list(map(int,input().split()))
hyoko = list(map(int,input().split()))
road = [0]*word[1]
for i in range(word[1]):
    road[i] = list(map(int,input().split()))
tenbo = [1]*word[0]

for j in range(word[1]):
    if hyoko[road[j][0]-1] > hyoko[road[j][1]-1]:
        tenbo[road[j][0]-1] *= 1
        tenbo[road[j][1]-1] = 0
    elif hyoko[road[j][0]-1] < hyoko[road[j][1]-1]:
        tenbo[road[j][0]-1] = 0
        tenbo[road[j][1]-1] *= 1
answer = word[0] - tenbo.count(0)
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

arr = [0]*M
for i in range(M):
    arr[i] = max(H[AB[i][0]-1], H[AB[i][1]-1])
#print(arr)
print(len(set(arr)))

Submission status: Wrong Answer

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

"""
0: 初期値
1: highest
-1: not highest
"""
for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    if h[a] > h[b] and res[a] == 0:
        res[a] = 1
        res[b] = -1
    elif h[a] < h[b] and res[b] == 0:
        res[a] = -1
        res[b] = 1
    elif h[a] == h[b]:
        res[a] = -1
        res[b] = -1

print(res.count(1) + res.count(0))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
g=[1]*n
for i in range(m):
    a,b=map(int,input().split())
    if a>b:
        g[b]=0
    if b>a:
        g[a]=0
print(sum(g))

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 _ in range(m)]
flag = [0]*n
for i in range(m):
  if H[a[i][0]-1] > H[a[i][1]-1]:
    flag[a[i][0]-1] = 2
    #flag[a[i][1]-1] = 
  elif H[a[i][0]-1] == H[a[i][1]-1]:
    flag[a[i][0]-1] = 2
    flag[a[i][1]-1] = 2
  else:
    flag[a[i][0]-1] = 2
    #flag[a[i][1]-1] = 1
cnt = 0
for j in range(n):
  if flag[j] == 0:
    cnt += 1
print(cnt)

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 _ in range(m)]
flag = [0]*n
for i in range(m):
  if H[a[i][0]-1] > H[a[i][1]-1]:
    flag[a[i][0]-1] = 1
    flag[a[i][1]-1] = 2
  elif H[a[i][0]-1] == H[a[i][1]-1]:
    flag[a[i][0]-1] = 2
    flag[a[i][1]-1] = 2
  else:
    flag[a[i][0]-1] = 2
    flag[a[i][1]-1] = 1
cnt = 0
for j in range(n):
  if flag[j] == 1 or flag[j] == 0:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = []

for i in range(M):
    A0, B0 = map(int, input().split())
    A.append(A0)
    B.append(B0)

C = [[i] for i in range(N)]
HC = [[H[i]] for i in range(N)]
for i in range(M):
    C[A[i]-1].append(B[i]-1)
    C[B[i]-1].append(A[i]-1)
    HC[A[i]-1].append(H[B[i]-1])
    HC[B[i]-1].append(H[A[i]-1])
   
cnt = 0    
for i in range(N):
    C0 = []
    HC0 = []
    for cc,hcc in sorted(zip(C[i],HC[i]),key=itemgetter(1)):
       C0.append(cc)
       HC0.append(hcc)
    C[i] = C0
    HC[i] = HC0
    if C[i][0] == i:
        cnt += 1
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
height = list(map(int,input().split()))
bet,cost = [],[0]*N
for i in range(M):
     bet.append(list(map(int,input().split())))

for b in bet:
    if height[b[0]-1] < height[b[1]-1]:
        cost[b[1]-1] = 1
        cost[b[0]-1] = 0
    else:
        cost[b[0]-1] = 1
        cost[b[1]-1] = 0

print(cost.count(1))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
height = list(map(int,input().split()))
bet,cost = [],[0]*N
for i in range(M):
     bet.append(list(map(int,input().split())))

for b in bet:
    if height[b[0]-1] < height[b[1]-1]:
        cost[b[1]-1] = 1
    else:
        cost[b[0]-1] = 1

print(cost.count(1))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
height = list(map(int,input().split()))
bet,cost = [],[0]*N
for i in range(M):
     bet.append(list(map(int,input().split())))

for b in bet:
    if height[b[0]-1] < height[b[1]-1]:
        cost[b[1]-1] = 1
    else:
        cost[b[0]-1] = 1

print(cost)

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)]
chk = [[] for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(m):
        if i+1 in ab[j]:
            chk[i].extend(ab[j])
    chk[i] = list(set(chk[i]))
cnt = 0
for i in range(n):
    for j in range(len(chk[i])):
        if h[i] > h[chk[i][j]-1]:
            cnt += 1
    if cnt == len(chk[i])-1:
        ans += 1
print(ans+1)

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)]
gp = []
for i in range(len(ab)):
    a,b = ab[i][0],ab[i][1]
    good = max(h[a-1],h[b-1])
    gp.append(good)

print(len(list(set(gp))))

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
path = [[] for _ in range(n)]
for i in range(m):
    a, b = list(map(int, input().split()))
    if h[a - 1] < h[b - 1]:
        path[a - 1].append(False)
        path[b - 1].append(True)
    else:
        path[a - 1].append(True)
        path[b - 1].append(False)
ans = 0
for i in path:
    if all(i):
        ans += 1
print(ans)

Submission status: Wrong Answer

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

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 _ in range(M)]

H_list = []
ans = []

for t in A_B:
  T = []
  T1 = T.append(H[t[0]-1])
  T2 = T.append(H[t[1]-1])
  H_list.append(T)
  if T[0] == T[1]:
    continue
  elif T[0] > T[1]:
    ans.append(T[0])
  else:
    ans.append(T[1])

H_list2 = list(set(sum(H_list,[])))
H_last = list(set(H_list2)^set(H))
if H_last != []:
  ans.append(H_last[0])
else:
  pass
print(len(set(ans)))

Submission status: Wrong Answer

Solution code:
number=list(map(int,input().split()))
n,m=number[0],number[1]
height=list(map(int,input().split()))
load=[[] for i in range(n+1)]
for i in range(m):
    tmp=list(map(int,input().split()))
    if tmp[1] not in load[tmp[0]]:
        load[tmp[0]].append(tmp[1])
    if tmp[0] not in load[tmp[1]]:
        load[tmp[1]].append(tmp[0])

box=[]
answer=0
for i in range(1,n+1):
    box=[]
    for j in range(len(load[i])):
        box.append(height[load[i][j]-1])
    if box!=[]:
        if max(box)<=height[i-1]:
            answer+=1
print(answer)

Submission status: Wrong Answer

Solution code:
number=list(map(int,input().split()))
n,m=number[0],number[1]
height=list(map(int,input().split()))
load=[[] for i in range(n+1)]
for i in range(m):
    tmp=list(map(int,input().split()))
    if tmp[1] not in load[tmp[0]]:
        load[tmp[0]].append(tmp[1])
    if tmp[0] not in load[tmp[1]]:
        load[tmp[1]].append(tmp[0])


answer=0

for i in range(1,n+1):
    while load[i] != []:
        if height[i-1]<height[load[i][-1]-1]:
            break
        load[i].pop()
        if load[i] == []:
            answer+=1
        
print(answer)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ht = list(map(int, input().split()))
rd = [list(map(int, input().split())) for _ in range(m)]
gob = 0
for i in range(n):
    for j in range(m):
        if i + 1 in rd[j]:
            if ht[i] != max(ht[rd[j][0] - 1], ht[rd[j][1] - 1]):
                break
        else:
            continue
        gob += 1
        break
print(gob)

Submission status: Wrong Answer

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

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