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:

def input_from_console():
    n, m = map(int, input().split())
    ab_list = []
    h_list = map(int, input().split())
    for i in range(m):
        a,b = map(int, input().split())
        ab_list.append((a, b))
    return n, m, list(h_list), list(ab_list)


def solve(n, m, h_list, ab_list):
    good_observatory = [True] * n
    good_observatory[0] = False
    for (a, b) in ab_list:
        if h_list[a-1] < h_list[b-1]:
            good_observatory[a - 1] = False
        if h_list[a-1] > h_list[b-1]:
            good_observatory[b - 1] = False
        if h_list[a-1] == h_list[b-1]:
            good_observatory[a - 1] = False
            good_observatory[b - 1] = False

    return sum(good_observatory)


def main():
    n, m, h_list, ab_list = input_from_console()
    print(solve(n, m, h_list, ab_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Wrong Answer

Solution code:
inp=input
li=list
iinp=lambda : int(inp())
ent=lambda : map(int,inp().split())
lient=lambda : [int(i) for i in inp().split()]
li0= lambda x: [0 for i in range(x)]
livalor=lambda valor,x: [valor for i in range(x)]
stent=lambda : [i for i in inp()]
filldp=lambda valor,x,y: [[valor for i in range(y)] for i in range(x)]

cantobservatorios,caminos=ent()
alturas=lient()
mapa=filldp(0,cantobservatorios,cantobservatorios)
for i in range(caminos):
    a,b=ent()
    mapa[a-1][b-1]+=1
    mapa[b-1][a-1]+=1
res=0

for i in range(cantobservatorios):
    tmp=0
    ban=False
    for j in range(cantobservatorios):
        if mapa[i][j]==0:tmp+=1
        elif mapa[i][j]==1:
            if alturas[i]>alturas[j]:
                ban=True
            else:
                ban=False
                break
        else:
            ban=False
            break
    if tmp==cantobservatorios: res+=1
    if ban:res+=1
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    A = [[]] * N
    for i in range(M):
        pp, ss = map(int, input().split())
        ss -= 1
        pp -= 1
        A[pp] = A[pp] + [ss]
        A[ss] = A[ss] + [pp]

    ans = 0
    for j in range(N):
        now = H[j]
        if not A[j]:
            ans += 1
            continue

        tmp = 0

        for road in set(A[j]):
            if (now > H[road]):
                tmp += 1

        if tmp == len(A[j]):
            ans += 1

    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
s = list(map(int,input().split()))
n=s[0]
m=s[1]
h = list(map(int, input().split()))
p=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    s = list(map(int, input().split()))
    p[s[0]][s[1]]=1
    p[s[1]][s[0]]=1
ans=-1
for i in range(n+1):
    flag=0
    if max(p[i][:])==0:
        flag=1
    for j in range(n):
        if p[i][j]==1:
            # print(h[i-1],h[j-1])
            if h[i-1]<=h[j-1]:
                flag=0
            else:
                flag=1
    if flag==1:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

cnt=0
for i in range(N):
    flg=False
    #print(i)
    for j in A:
        #print(j)
        if (j[0]==i+1 and H[i]>H[j[1]-1]) or (j[1]==i+1 and H[i]>H[j[0]-1]) :
            flg=True
    if flg==True:
        #print(i+1)
        cnt+=1
# どの展望台とも接続しない
for i in range(N):
    flg=True
    for j in A:
        if not j.count(i+1)==0:
            flg=False
    if flg==True:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
H= input().split()
B= [0]*M
count=0
for i in range(M):
  B[i]= input().split()
for i in range(N):
  YN = 1
  for j in range (M):
    if B[j][0] == H[i]:
      if B[j][1] >= H[i]:
        YN = 0
    elif B[j][1] == H[i]:
      if B[j][0] >= H[i]:
        YN = 0
  if YN == 1:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
ok = [0]*n
count = 0
check = [0]*n
for i in range(m):
    x, y = list(map(int, input().split()))
    if h[x-1] > h[y-1]:
        ok[x-1] = 1
    if h[y-1] > h[x-1]:
        ok[y-1] = 1
    check[x-1] += 1
    check[y-1] += 1

for i in range(n):
    if ok[i] == 1:
        count += 1

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

# print(ok)
# print(check)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
ABlist=[]
count=N
for i in range(M):
  ABlist.append(list(map(int,input().split())))
#print(N,M)
#print(H)
#print(ABlist)

for h in H:
  for m in ABlist:
    if h==m[0] and h<m[1]:
      count=count-1
      break
    elif h==m[1] and h<m[0]:
      count=count-1
      break

print(count)

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
    elif(H[A-1]==H[B-1]):
        H01[A-1] = 0
        H01[B-1] = 0
    else:
        H01[A-1] = 1
        H01[B-1] = 0
print(sum(H01))

Submission status: Wrong Answer

Solution code:
def main():
    n, m = [int(x) for x in input().split()]
    heights = tuple(int(x) for x in input().split())
    adjacents_heights = [set() for _ in range(n)]
    print(heights)
    for i in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        adjacents_heights[a].add(heights[b])
        adjacents_heights[b].add(heights[a])
    ans = 0
    print(adjacents_heights)
    for h, ahs in zip(heights, adjacents_heights):
        if not ahs:
            ans += 1
            continue
        elif h > max(ahs):
            ans += 1

    return ans


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math
read = sys.stdin.readline

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

t = [0] * N 
for m in range(M):
    if H[ lo[m][0] - 1 ] > H[ lo[m][1] - 1 ]:
        if t[lo[m][0] - 1 ] != -1 :
            t[lo[m][0] - 1] = 1
            t[lo[m][1] - 1] = -1
        continue 

    if H[ lo[m][0] - 1 ] < H[ lo[m][1] - 1 ]:
        if t[lo[m][1] - 1 ] != -1 :
            t[lo[m][0] - 1] = -1
            t[lo[m][1] - 1] = 1
        continue 

    if H[ lo[m][0] - 1 ] == H[ lo[m][1] - 1 ]:
        if t[lo[m][1] - 1 ] != -1 :
            t[lo[m][0] - 1] = -1
            t[lo[m][1] - 1] = -1
        continue 

good = 0
for i in t:
    if i != -1:
        good += 1

print(good)

Submission status: Wrong Answer

Solution code:
N, M = [int(n) for n in input().split()]
Hs = [int(n) for n in input().split()]
# len(Hs) = N = 展望台の数
# M = 展望台同士を結ぶ道の数
not_good = set()
for i in range(0, M):
    A, B = [int(n) for n in input().split()]
    if Hs[A-1] > Hs[B-1]:
        not_good.add(B)
    else:
        not_good.add(A)
ans = N-len(not_good)
print(ans)

Submission status: Wrong Answer

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

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

print(sum(l))

Submission status: Wrong Answer

Solution code:
line = input().split(" ")
#展望台の個数
N = int(line[0])
#道の個数
M = int(line[1])

isnum = [True] * N

h_list = input().split(" ")
count = 0
for i in range (M):
  a = input().split(" ")
  if int(h_list[int(a[0])-1]) == int(h_list[int(a[1])-1]):
    isnum[int(a[0]) - 1] = False
    isnum[int(a[1]) - 1] = False
    continue
  elif int(h_list[int(a[0])-1]) < int(h_list[int(a[1])-1]):
    isnum[int(a[0]) - 1] = False
n = sum(x==True for x in isnum)
print(n)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
dic=defaultdict(list)
for i in range(m):
    a,b=[int(i) for i in input().split()]
    dic[a].append(b)
    dic[b].append(a)
c=0

for i in range(n):
    if h[i] not in dic:
        c+=1
    elif h[i] in dic:
        a=h[i]
        b=a
        for j in dic[h[i]]:
            if j>b:
                b=j
        if b==a:
            c+=1
print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = []
for _ in range(m):
    a, b = map(int, input().split())
    if h[a-1] > h[b-1]:
        ans.append(b-1)
    elif h[a-1] < h[b-1]:
        ans.append(a - 1)
    else:
        ans.append(a - 1)
        ans.append(b - 1)
print(len(set(ans)))

Submission status: Wrong Answer

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

for _ in range(M):
    A, B = map(int, input().split())
    route[A-1] = 1
    route[B-1] = 1
    if H[A-1] > H[B-1]:
        result[A-1] = 1
        result[B-1] = 0
    elif H[A-1] < H[B-1]:
        result[A-1] = 0
        result[B-1] = 1
    else:
        result[A-1] = 0
        result[B-1] = 0

print(result.count(1) + route.count(0))

Submission status: Wrong Answer

Solution code:
def c166(n, m, hl, abli):

    flag = [True]*n

    for i in abli:
        if hl[i[0]-1] < hl[i[1]-1]:
            flag[i[0]-1] = False
        else:
            flag[i[1]-1] = False

    ans = flag.count(True)
    return ans

def main():
    n, m = map(int, input().split())
    hl = list(map(int, input().split()))
    abli = [list(map(int, input().split()))for i in range(m)]
    print(c166(n, m, hl, abli))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = h[:]
for i in range(m):
  a, b = map(int, input().split())
  l[a-1] = max(l[a-1], l[b-1])
  l[b-1] = max(l[a-1], l[b-1])
  
print(len(set(l)))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

n,m = LI()
h = [i-1 for i in LI()]
ans = []
for i in range(m):
    a,b = [j-1 for j in LI()]
    t = h.index(max(h[a], h[b]))
    ans.append(t)
print(len(set(ans)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [1] * n
l = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    x = h[a-1]
    y = h[b-1]
    if x < y:
        ans[a-1] = 0
    else:
        ans[b-1] = 0
print(len(ans) - sum(ans))

Submission status: Wrong Answer

Solution code:
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush

import collections
# T = int(stdin.readline())
# for i in range(T):
    #N=int(stdin.readline())
N,M=list(map(int,stdin.readline().split()))
hill=list(map(int,stdin.readline().split()))

dc=collections.defaultdict(list)
#vis=set()
for m in range(M):
    A,B=list(map(int,stdin.readline().split()))
    dc[A].append(B)
    dc[B].append(A)

ans=0
for k,ls in dc.items():
    if len(ls)==len(set(ls)):
        f=0
        for h in ls:
            if hill[k-1]<=hill[h-1]:
                f=1
                break
        if not f:
            ans+=1  

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = [0] + list(map(int, input().split())) 
AB = [tuple(map(int, input().split())) for _ in range(M)]
good_num = N
pair = [set(e)  for e in set(AB)]
bad_tenbodai = []
for a,b in pair:
    if H[a] < H[b]:
        bad_tenbodai.append(a)
    else:
        bad_tenbodai.append(b)
print(N - len(set(bad_tenbodai)))

Submission status: Wrong Answer

Solution code:
# AtCoder
from collections import defaultdict
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
d = defaultdict(set)

for i in range(M):
    d[H[AB[i][0]-1]].add(AB[i][1])
    d[H[AB[i][1]-1]].add(AB[i][0])

cnt = 0
for k, v in d.items():
    if k > max(v):
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:

def main():
    N, M = list(map(int, input().split(' ')))
    
    Hn = list(map(int, input().split(' ')))
    
    ABn = []
    for _ in range(M):
        ABn.append(list(map(int, input().split(' '))))
    
    dic_path = {i+1:[] for i in range(len(Hn))}
    
    for i in range(M):
        a = ABn[i][0]
        b = ABn[i][1]
        
        dic_path[a].append([a, b])
        dic_path[b].append([b, a])
    
    
    result = 0
    for i, paths in dic_path.items():
        
        if len(paths) == 0:
            result += 1
            break
        
        for path in paths:
            
            
        
            
            a, b = path[0], path[1]
            ha, hb = Hn[a-1], Hn[b-1]
            # print('a, b, ha, hb:', a, b, ha, hb)
            
            if ha < hb:
                break
            elif ha > hb:
                # print('a, b, ha, hb:', a, b, ha, hb)
                result += 1
                break
    print(result)
                
                
                
        
        
        
        

        
    
    



main()

Submission status: Wrong Answer

Solution code:
N_ko, M_hon = map(int, input().split())
Heights = list(map(int, input().split()))
indexs = [[0 for i in range(N_ko)] for j in range(N_ko)]


for i in range(M_hon):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    
    indexs[a][b] = 1
    indexs[b][a] = 1
    

ans = 0
saikou = []

for i in range(N_ko):
    if (indexs[i].count(1) == 0):
        ans += 1
        saikou.append(i)
    else:
        maxx = 0
        max_i = -1

        for j in indexs[i]:
            h = Heights[j]
            if (h > maxx):
                max_i = j
                maxx = h
        
        if (saikou.count(max_i) == 0):
            saikou.append(max_i)
            ans += 1

print(ans+1)

Submission status: Wrong Answer

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

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

print(sum(ans))

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)]
dp = [0]*N

for i in range(M):
    dp[AB[i][0]-1] = max(dp[AB[i][0]-1],H[AB[i][1]-1])
    dp[AB[i][1]-1] = max(dp[AB[i][1]-1],H[AB[i][0]-1])

ans = 0
for i in range(N):
    if H[i]-dp[i]>0:
        ans +=1
    elif dp[0]==0:
        ans +=1
print(ans)

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())
  if h[a-1]>h[b-1]:
        ans[b-1]+=1
  elif h[a-1]<h[b-1]:
        ans[a-1]+=1
print(ans.count(0))

Submission status: Wrong Answer

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

for __ in range(M):
    _A, _B = map(int,input().split())
    A.append(_A)
    B.append(_B)
    

for i in range(M):
    if H[A[i] - 1] > H[B[i] - 1]:
        flag[A[i] - 1] = 1
    else:
        flag[B[i] - 1] = 1        
print(sum(flag))

Submission status: Wrong Answer

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

for i in range(M):
    if H[AB[i][0]-1] > H[AB[i][1]-1]:#dictにするか？
        Hi[AB[i][1]-1] = 0
    else:
        Hi[AB[i][0]-1] = 0
print(sum(Hi))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H_ = list(map(int,input().split()))
H = [0]
H.extend(H_)
D = dict()
for i in range(M):
    t_ = list(map(int,input().split()))
    if t_[0] not in D.keys():
        D[t_[0]] = [t_[1]]
    else:
        D[t_[0]].append(t_[1])
    if t_[1] not in D.keys():
        D[t_[1]] = [t_[0]]
    else:
        D[t_[1]].append(t_[0])
ret = list()
for v in D.keys():
    L = D[v]
    for i in range(len(L)):
        if H[v] < H[L[i]]:
            break
        if i == len(L) - 1:
            ret.append(v)
num = N - len(D.keys()) + len(ret)
print(num)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = [int(i) for i in input().split()]
G = [0]*N

for i in range(M):
    A, B = map(int, input().split())
    if A>B: G[A-1] = 1
    else: G[B-1] = 1

print(G.count(1))

Submission status: Wrong Answer

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

D = set(W)
q = N - len(D)
S = []
for j in range (M):
    if H[A[j]-1] > H[B[j]-1]:
        if (S.count(A[j]) == 0):
            S.append(A[j])
        
        if (S.count(B[j]) == 1):
            S.remove(B[j])
    elif H[A[j]-1] < H[B[j]-1]:
        if (S.count(B[j]) == 0):
            S.append(B[j])
        if (S.count(A[j]) == 1):
            S.remove(A[j])

print(len(S)+q)

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]:
    lst[a-1]=-1
    lst[b-1]+=1
  elif height[a-1]>height[b-1]:
    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
for k in range(n):
  if lst[k]>=0:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

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

for i in range(len(h)):
    tmph = h[i]
    flg = 1
    if arr[i]:
        for j in arr[i]:
            if tmph <= h[j]:
                flg = 0
                break
    if flg == 1:
        ans +=1
        print(i)
print(ans)

Submission status: Wrong Answer

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

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

ans = set()
for i in range(n):
    stack = table[i]
    highest = h[i]
    flag = True
    if len(table[i]) == 0:
        continue
    for t in table[i]:
        if highest < h[t]:
            flag = False
            break
    if flag:
        ans.add(i)
print(len(ans))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
connection = [0 for _ in range(N)]
cnt = 1
for _ in range(M):
    A, B = map(int, input().split())
    if connection[A-1] != 0:
        tmp = connection[A-1]
        if connection[B-1] != 0:
            b_connect = connection[B-1]
            for idx, i in enumerate(connection):
                if i == b_connect:
                    connection[idx] = tmp
        else:
            connection[B-1] = tmp
    else:
        if connection[B-1] != 0:
            tmp = connection[B-1]
            connection[A-1] = tmp
        else:
            connection[A-1], connection[B-1] = cnt, cnt
            cnt += 1

result = 0

for i in connection:
    if i == 0:
        result += 1

if result > 0:
    result = result + cnt -1
else:
    result = result + cnt
print(result)

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
    if h[a[i] - 1] > h[b[i] - 1]:
        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())
h = list(map(int,input().split()))
hbox = []
for i in h:
    a = [i]
    hbox.append(a)
for j in range(m):
    a,b = map(int, input().split())
    hbox[a-1].append(h[b-1])
    hbox[b-1].append(h[a-1])
for l in range(n):
    hbox[l] = sorted(hbox[l])
ans = 0
for k in range(n):
    if len(hbox[k]) >1:
        if h[k] == hbox[k][-1] and hbox[k][-2]:
            ans += 1
    else:
        if h[k] == hbox[-1]:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = []
for i in range(M):
    A, B = map(int, input().split())
    ans.append(max(H[A-1], H[B-1])) # 大きい方を入れる
print(len(set(ans)))

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
    elif H[a-1]==H[b-1]:
        li[a]=-4
        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:
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def factorization(n):
	tmp=n
	count=0
	for i in range(2,int(n**0.5)+2):
		if tmp%i==0:
			cnt=0
			while tmp%i==0:
				cnt+=1
				tmp//=i
			count+=1
	if tmp!=1:
		count+=1

	return count
			


n,m=input2()
H=input_array()
# G=[[0]*n]*n #グラフ
counts=[]
l=[]
for i in range(m):
	a,b=input2()
	l+=[a,b]
	if H[a-1]>H[b-1]:
		counts.append(a-1)
	elif H[a-1]<H[b-1]:
		counts.append(b-1)

ones=n-len(Counter(l))
print(len(Counter(counts)) + ones)

Submission status: Wrong Answer

Solution code:
def c166(n, m, hl, abli):

    flag = [True]*n

    for i in abli:
        if hl[i[0]-1] < hl[i[1]-1]:
            flag[i[1]-1] = False
        else:
            flag[i[0]-1] = False

    ans = flag.count(True)
    return ans

def main():
    n, m = map(int, input().split())
    hl = list(map(int, input().split()))
    abli = [list(map(int, input().split()))for i in range(m)]
    print(c166(n, m, hl, abli))

if __name__ == '__main__':
    main()

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

b = [[] for i in range(n)]
ans=[0]*n
for x,y in a:
    b[x-1].append(y-1)
    b[y-1].append(x-1)


for i in range(n):
    x=[]
    x.append([i,h[i]])
    for j in b[i]:
        x.append([j,h[j]])
    x.sort(key=lambda x:x[1])
    x.reverse()
    if ans[x[0][0]]==0:
        if len(x)==1:
            ans[x[0][0]]=1
        else:
            if x[1][1]!=x[0][1]:
                ans[x[0][0]]=1


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

print(cnt)

Submission status: Wrong Answer

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

ans = [[i] for i in h]

for i in path:
    ans[i[0]-1].append(h[i[1]-1])
    ans[i[1]-1].append(h[i[0]-1])

count = 0
for i in ans:
    if i[0] == max(i):
        count += 1

print(count)

Submission status: Wrong Answer

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

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

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
raw_obs_dic = {i+1: [] for i in range(n)}
for i in range(m):
	a,b = [int(e) for e in input().split(" ")[:2]]
	raw_obs_dic[a].append(b)
	raw_obs_dic[b].append(a)

# unique
obs_dic = {k:list(set(raw_obs_dic[k])) for k in raw_obs_dic}
print(obs_dic)

cnt = 0
for o0 in obs_dic:
	# # no obs
	# if len(obs_dic[o0]) < 1:
	# 	flag = True
	# 	continue
	# compare height
	o0_h = h_ls[o0-1]
	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 = [int(h) for h in input().split()]

d = {}

for i in range(N):
    d[i+1] = H[i]

for _ in range(M):
    A,B = map(int,input().split())

    if H[B-1] > H[A-1]:
        d[A] = 0

    elif H[B-1] < H[A-1]:
        d[B] = 0


print(N - list(d.values()).count(0))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

s = list(map(int, input().split(" ")))

tnb = s[0]
mc = s[1]

hk = list(map(int, input().split(" ")))
v = []
for i in range(mc) :
    tmp = list(map(int, input().split(" ")))
    x = tmp[0] - 1
    y = tmp[1] - 1
    ap = y
    if hk[x] < hk[y] :
        ap = x
    v.append(ap)

ans = tnb - len(set(v))
print(ans)

Submission status: Wrong Answer

Solution code:
#C問題
N,M = map(int, input().split())
H = input().split()
result = [False] * N
H_i = [int(s) for s in H]
bothCount = 0
for i in range(M):
    A,B = map(int, input().split())
    if(H_i[A-1] > H_i[B-1]):
        #AがBよりも高かったらAがいい展望台
        result[A-1] = True
    elif(H_i[A-1] < H_i[B-1]):
        result[B-1] = True
    else:
        result[A-1] = True
Count = 0
Count = result.count(True)
print(Count)

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(len([x for x in r if 1 <= x]))

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]:
    lst[a-1]=-1
    lst[b-1]+=1
  elif height[a-1]>height[b-1]:
    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 numpy as np

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

ans = np.array([1 for _ in range(N)])
for i in range(M):
	A, B = map(int, input().split())
	if H[A-1] < H[B-1]:
		ans[B-1] = 1
		ans[A-1] = 0
	elif H[A-1] > H[B-1]:
		ans[A-1] = 0
		ans[B-1] = 1
	else:
		ans[A-1], ans[B-1] = 0, 0

print(np.sum(ans == 1))

Submission status: Wrong Answer

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

for _ in range(n):
  if sum([o for o in lst[_] if o >= _]) == 0:
    i += 1
print(i)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
hm = {i + 1: hi for i, hi in enumerate(list(map(int, input().split())))}
bad_h = []
for i in range(m):
    ai, bi = list(map(int, input().split()))
    if hm[ai] < hm[bi]:
        k = ai
    else:
        k = bi
    bad_h.append(k)
print(len(hm) - len(set(bad_h)))