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())
tenbou=[1]*n

h = list(map(int,input().split()))
for i in range(1,m+1):
  ab = list(map(int,input().split()))
  if (h[ab[0]-1] >= h[ab[1]-1]):
    tenbou[ab[0]-1]=0
  else:
    tenbou[ab[1]-1]=0

print(tenbou.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 i in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

minus = 0

for i in range(n):
    height = h[i]
    if graph[i]:
        for j in graph[i]:
            if i == j:
                continue
            if h[j] > height:
                minus += 1
                break
    else:
        minus += 1
        continue

print(n-minus)

Submission status: Wrong Answer

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

AB = []
for i in range(M):
    AB.append(list(map(int, input().split())))
    
max_H = [H[i] for i in range(N)]
for i in range(M):
    A, B = AB[i]
    max_H[A-1] = max(max_H[A-1], H[A-1], H[B-1])
    max_H[B-1] = max(max_H[B-1], H[A-1], H[B-1])

max_H = set(max_H)
print(len(max_H))

Submission status: Wrong Answer

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

NN = [0]*N
for i in range(N):
  NN[i] = i

for i in range(M):
  if Roads[i][0] > Roads[i][1]:
    Roads[i][0], Roads[i][1] = Roads[i][1], Roads[i][0]
  NN[Roads[i][1]-1] = NN[Roads[i][0]-1]

NN_unique = NN.copy()
NN_unique = list(set(NN))

cnt = 0
for n in NN_unique:
  HH_unique = []
  for i in range(N):
    if NN[i] == n:
      HH_unique.append(HH[i])
  #print(n,HH_unique)
  Hmx = max(HH_unique)
  cnt += HH_unique.count(Hmx)
print(cnt)

Submission status: Wrong Answer

Solution code:
import copy
n, m = map(int, input().split())
h0 = list(map(int, input().strip().split()))

h = copy.deepcopy(h0)

for i in range(m):
    a, b = map(int, input().split())
    c = max(h[a-1],h[b-1])
    h[a-1] = c
    h[b-1] = c

#print(h0)
#print(h)


ans = 0
for i in range(n):
    if h[i] == h0[i]:
        #print(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())
  ans[A-1]=0
  ans[B-1]=0
  if H[A-1]>H[B-1]:
    ans[A-1]=1
    ans[B-1]=0
  elif H[A-1]<H[B-1]:
    ans[A-1]=0
    ans[B-1]=1
  else:
    ans[A-1]=0
    ans[B-1]=0
print(ans.count(1))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = n
ls = []
for i in range(m):
    a,b = map(int,input().split())
    ls.append([a,b])
    if h[a-1] < h[b-1] and h[a-1] != 0 and h[b-1] != 0:
        h[a-1] = 0
        ans -= 1
    elif h[a-1] > h[b-1] and h[a-1] != 0 and h[b-1] != 0:
        h[b-1] = 0
        ans -= 1
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

co2 = (len(get_unique_list(ls)))
co = len(ls)
#co2 = set(ls)
#print(co2)
print(ans-(co-co2))

Submission status: Wrong Answer

Solution code:
a, b = list(map(int, input().split()))
l = list(map(int, input().split()))
best = []
for i in range(b):
    x, y = list(map(int, input().split()))
    best.append(l.index(max(l[x - 1], l[y - 1])))

print(len(set(best)))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
H = [int(a) for a in input().split()]
good = np.zeros(N, dtype=int)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if H[a] > H[b]:
        good[b] += 1
    elif H[a] < H[b]:
        good[a] += 1

ans = 0
for i in good:
    if i == 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
road = [list(map(int,input().split())) for r in range(M)]
ans = []
for r in road:
	if H[r[0]-1] > H[r[1]-1]:
		ans.append(r[0])
	elif H[r[0]-1] < H[r[1]-1]:
		ans.append(r[1])
print(len(set(ans)))

Submission status: Wrong Answer

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

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

l = [1 for i in range(N)]
for ab in AB:
    a = ab[0]-1
    b = ab[1]-1

    if H_list[a] < H_list[b]:
        l[a] = 0
    else:
        l[b] = 0

print(sum(l))

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())
ans = [1]*n
h = input().split()
h_int = [int(s) for s in h]
cou = 0

for i in range(m):
  x,y = map(int,input().split())
  if h_int[x-1] >= h_int[y-1]:
    ans[y-1] = 0
  elif h_int[y-1] >= h_int[x-1]:
    ans[x-1] = 0

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

print(cou)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
tmpArr=[]
while m>0:
  m-=1
  tmpArr.append(list(map(int,input().split())))
ans=[]
for a,b in tmpArr:
  #print (a,b)
  if a in h and b in h:
    if h.index(a)>h.index(b):
      ans.append(a)
      if b in ans:
        ans.remove(b)
    else:
      ans.append(b)
      if a in ans:
        ans.remove(a)
  elif a in h:
    ans.append(a)
  elif b in h:
    ans.append(b)
  
print (len(set(ans)))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    H=[int(_) for _ in input().split()]
    HH= [0]*n

    for i in range(m):
        a,b=map(int,input().split())
        HH[a-1]=max(HH[a-1],H[b-1])
        HH[b-1]=max(HH[b-1],H[a-1])
    ans=0
    for i,hh in enumerate(HH):
        if H[i]>hh or hh==0:
            ans+=1
    print(HH)
    print(ans)

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:
# Problem C - Peaks

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

# initialization
score_list = [0]*N
for i in range(M):
    a, b = map(int, input().split())
    if h_list[a-1]<h_list[b-1]:
        if h_list[b-1]>=0:
            score_list[b-1] += 1
        else:
            score_list[b-1] = -1
        score_list[a-1] = -1
    elif h_list[a-1]>h_list[b-1]:
        if h_list[a-1]>=0:
            score_list[a-1] += 1
        else:
            score_list[a-1] = -1
        score_list[b-1] =  -1
    else:
        score_list[a-1] = -1
        score_list[b-1] = -1

# output
ans = 0
for s in score_list:
    if s>=0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
nn = [[-1]]*n

for i in range(m):
    a,b = map(int,input().split())
    nn[a-1].append(b-1)
    nn[b-1].append(a-1)
c=0
for i in range(n):
    f=0
    for k in nn[i]:
        if k==-1:
            continue
        if h[i] < k:
            f=1
    if f==0:
        c+=1
print(c)

Submission status: Wrong Answer

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

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

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

print(cnt)

Submission status: Wrong Answer

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


good = [0] * N

for i in range(M):
  ab = sorted(list(map(int,input().split())))
  if ab not in AB and ab[0] != ab[1]:
    AB.append(ab)

yet = list(set(sum(AB,[])))
yetnot = [i for i in range(1,N + 1) if i not in yet]

for i in range(len(AB)):
  A = AB[i][0] - 1
  B = AB[i][1] - 1
  if H[A] > H[B]:
    good[A] = 1
    good[B] = 0
  elif H[A] < H[B]:
    good[A] = 0
    good[B] = 1
  else:
    good[A] = 0
    good[B] = 0
  
good = [i for i in good if i == 1]
  
ans = len(good) + len(yetnot)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def main():
    N, M = list(map(int, input().split(' ')))
    H = list(map(int, input().split(' ')))
    obs = defaultdict(list)
    for _ in range(M):
        A, B = list(map(int, input().split(' ')))
        A -= 1
        B -= 1
        obs[A].append(B)
        obs[B].append(A)
    cnt = 0
    for i in range(N):
        obs_list = obs[i]
        if len(obs_list) == 0:
            cnt += 1
            break
        h_i = H[i]
        to_be_counted = True
        for j in obs_list:
            if h_i <= H[j]:
                to_be_counted = False
                break
        if to_be_counted:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

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 = [0]*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())
H=list(map(int,input().split()))

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

ans=graph.count(0)
print(ans)

Submission status: Wrong Answer

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

G = [[] for i in range(N)]

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

ans = 0

for i in range(N):
    self_h = H[i]

    self_max_flag = True

    for to in range(len(G[i])):
        if (self_h <= H[to]):
            self_max_flag = False
        
    if (self_max_flag):
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:

def solve():
  n, m = map(int, input().split())
  h = list(map(int, input().split()))
  tenbo = []
  ans = 0
  bit = [0]*n
  for i in range(m):
    tenbo.append(list(map(int, input().split())))
  hoge = [[] for i in range(n)]
  for i in range(m):
    hoge[tenbo[i][0]-1].append(tenbo[i][1]-1)
    hoge[tenbo[i][1]-1].append(tenbo[i][0]-1)
  for i in range(n):
    if len(hoge[i]) == 0:
      ans += 1
    for j in hoge[i]:
      if h[i] <= h[j]:
        bit[i] = 1
        break
  print(bit.count(1)+ans)
  return 0

 
if __name__ == "__main__":
  solve()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Evaluation = [0] * N

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

count = 0    
for i in range(N):
  if Evaluation[i] == 0:
    count += 1

print(count)

Submission status: Wrong Answer

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

for m in range(M):
  A,B = map(int,input().split())
  if H[A-1] < H[B-1]:
    ans[A-1] = 0
  else:
    ans[B-1] = 0

print(sum(ans))

Submission status: Wrong Answer

Solution code:
#C
n,m = map(int,input().split())
h = list(map(int,input().split()))
r = []
for _ in range(m):
    a,b = map(int,input().split())
    r.append([a,b])
    
flg = [True for _ in range(n)]

for i in range(m):
    if h[r[i][0] - 1] >= h[r[i][1] - 1]:
        flg[r[i][1] - 1] = False
    else:
        flg[r[i][0] - 1] = False
        
print(flg.count(True))

Submission status: Wrong Answer

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

par = [-1] * n

# union-find
# xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


# xとyの属する集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        # sizeの大きい方をxとする
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


# xとyが同じ集合か判定
def same(x, y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]


# 初期化
# 根なら-size、子なら親の頂点


for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b)
ans = 1
for i in range(n):
    if i == find(i):
        ans += 1
print(ans)

Submission status: Wrong Answer

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

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

print(n - len(set(to_remove)))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h = list(map(int,input().split()))
ans,a=[],[]
for i in range(m):
    A,B=map(int,input().split())
    a.append(A)
    a.append(B)
    if h[A-1]>h[B-1]:
        ans.append(A-1)
    elif h[A-1]<h[B-1]:
        ans.append(B-1)
print(n-len(set(a))+len(set(ans)))

Submission status: Wrong Answer

Solution code:
N, M = [int(x) for x in input().split(" ")]
H = [int(x) for x in input().split(" ")]
lines = [[] for i in range(N)]

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

good_observatory_num = 0
for n in range(N):
    if len(lines[n]) == 0:
        good_observatory_num += 1
    else:
        is_good = True
        for oh in lines[n]:
            if oh >= H[n]:
                is_good = False
        
        if is_good:
            good_observatory_num += 1

print(good_observatory_num)

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):
  s = input().rstrip().split(' ')
  a=int(s[0])
  b=int(s[1])
  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
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 = input().split()
count = set()
for i in range(M):
    A,B = map(int, input().split())
    if H[A-1] == H[B-1]:
        count.add(A)
        count.add(B)
    elif H[A-1]>H[B-1]:
        count.add(B)
    else:
        count.add(A)
print(N-len(count))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
d={}
for i, x in enumerate(h):
    if d.get(x):
        d[x].append(i+1)
    else:
        d[x] = [i+1]
m_ = max(d.keys())
num=0
for _ in range(m):
    x = list(map(int, input().split()))
    if x[0] in d[m_] or x[1] in d[m_]:
        num += 1
print(num+1)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
l = np.ones(N)
for i in range(M):
  A, B = list(map(int,input().split()))
  if H[B-1] - H[A-1] <= 0:
    l[B-1] = 0
  elif H[B-1] - H[A-1] >= 0:
    l[A-1] = 0
print(int(l.sum()))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = map(int,input().split())
datas = []
for i in range(M):
    datas.append(max(list(map(int,input().split()))))
print(len(set(datas)))

Submission status: Wrong Answer

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

is_good = [True] * N

for i in range(M):
    a,b = list(map(int, input().split()))
    if Hs[a-1] < Hs[b-1]:
        is_good[a-1] = False
    elif Hs[a-1] == Hs[b-1]:
        is_good[a-1] = False
        is_good[b-1] = False

cnt = 0
for v in is_good:
    if v:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(values: List[Tuple[int, int]], elevations: List[int], nb_obs: int) -> int:
    nb_higher_obs = [0] * nb_obs
    for a, b in values:
        a -= 1
        b -= 1
        if elevations[a] >= elevations[b]:
            nb_higher_obs[b] += 1
        elif elevations[a] <= elevations[b]:
            nb_higher_obs[a] += 1
    return nb_higher_obs.count(0)


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    N, M = map(int, input().split())
    Hs = list(map(int, input().split()))
    assert len(Hs) == N
    values = []
    for _ in range(M):
        values.append(tuple(map(int, input().split())))
    result = solve(values, Hs, N)
    print(result)


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)

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):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
t=0
for i in range(n):
  C=[]
  for j in range(m):
    if A[j]==i:
      C.append(B[j])
    elif B[j]==i:
      C.append(A[j])
  D=set(C)
  E=[0]
  for k in D:
    E.append(H[k-1])
  if max(E) < H[i]:
    t+=1
print(t)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

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

  height = [i for i in list(map(int, input().split()))]

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

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

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())
H=list(map(int,input().split()))
road=[[] for i in range(N)]
toutatu=[0]*N
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
#print(road)

q=deque([])

def dfs(q,h):
  while(q):
    v=q.popleft()
    for x in road[v]:
      if(toutatu[x]==0):
        q.append(x)
        h=max(h,H[x])
        toutatu[x]=1
        dfs(q,h)
        
  return h
count=0
for i in range(N):
  if(toutatu[i]==0):
    q.append(i)
    #print(i)
    count+=1
    h=0
    dfs(q,h)
print(count+1)

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
  else:
    gooddict[b]=0

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

Submission status: Wrong Answer

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

ans = [0] * (n)
cnts = [0] * (n)
for i in range(len(ab)):
    a, b = ab[i]
    if H[a-1] > H[b-1]:
      ans[a-1] = 1

    elif H[b-1] > H[a-1]:
      ans[b-1] = 1
    cnts[a-1]+=1
    cnts[b-1]+=1
      
cnt = 0
for i in range(len(cnts)):
  if cnts[i] == 0:
    cnt += 1
    
print(sum(ans) + cnt)

Submission status: Wrong Answer

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

hi.sort(key=lambda x: -x[1])

connection = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    connection[a - 1].append(b - 1)
    connection[b - 1].append(a - 1)

flag = [0 for i in range(n)]
for ten in hi:
    if flag[ten[0]] == 0:
        flag[ten[0]] = 1
    for other in connection[ten[0]]:
        if flag[other] == 0:
            flag[other] = -1

print(len([i for i in range(n) if flag[i] ==1]))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
H = [int(a) for a in input().split()]
good = np.zeros(N, dtype=int)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    print(H[a], H[b])
    if H[a] > H[b]:
        good[b] += 1
    elif H[a] < H[b]:
        good[a] += 1

ans = 0
print(good)
for i in good:
    if i == 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

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

ls = [1 for _ in range(N)]

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

    ls[A - 1] = 0
    ls[B - 1] = 0
    
    if H[A - 1] < H[B - 1]:
        ls[B - 1] = 1
    elif H[A - 1] > H[B - 1]:
        ls[A - 1] = 1

print(sum(ls))

Submission status: Wrong Answer

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

dic = {}
for i in range(1,n+1):
    dic[i] = 1
for j in range(1,m+1):
    h_1,h_2 = map(int,input().split())
    if h[h_1-1] < h[h_2-1]:
        dic[h_1] = 0
    else:
        dic[h_2] = 0
lis = list(dic.values())

print(lis.count(1))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, M = MI()
    H = LI()
    A = [0] * M
    B = [0] * M
    H_G = [[] for i in range(N)]

    for i in range(M):
        A[i], B[i] = MI()

    for i in range(M):
        H_G[A[i]-1].append(B[i]-1)
        H_G[B[i]-1].append(A[i]-1)

    ans = 0

    for i in range(N):
        H_G[i] = sorted(H_G[i], reverse=True)
        # if len(H_G[i]) != 0:
        #     print('H', H[i], H_G[i][0])
        if len(H_G[i]) == 0:
            pass
        elif H[i] > H_G[i][0]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque

N, M = map(int, input().split())
H = [int(s) for s in input().split()]

edges = defaultdict(list)

for i in range(M):
    w = 1
    u, v = map(int, input().split())
    edges[u-1].append((v-1, w))
    edges[v-1].append((u-1, w))

# print(edges)

checked = [None] * N
checked[0] = 0

que = deque(range(N))

while que:
    u = que.popleft()
    c = True
   # print('check u=', u)
    for v, w in edges[u]:
       # print('++++ v=', v)
        # if checked[v] != None:
        #     continue
        # if edges[v] != []:
        #     que.append(v)
        if H[u] <= H[v]:
            c = False
    checked[u] = c

ans = 0
for i in range(N):
    if checked[i] == False or checked[i] == None:
        ans += 1

# print(checked)
print(ans)

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
    else:
        continue
    if flg == 1:
        ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
  n, m = map(int, input().split())
  h = list(map(int, input().split()))
  tenbo = []
  bit = [0]*n
  for i in range(m):
    tenbo.append(list(map(int, input().split())))
  hoge = [[] for i in range(n)]
  for i in range(m):
    hoge[tenbo[i][0]-1].append(tenbo[i][1]-1)
    hoge[tenbo[i][1]-1].append(tenbo[i][0]-1)
  for i in range(n):
    for j in hoge[i]:
      if h[i] <= h[j]:
        bit[i] = 1
        break
  print(bit.count(1))
  return 0

 
if __name__ == "__main__":
  solve()

Submission status: Wrong Answer

Solution code:
import collections
n,m = list(map(int,input().split()))
tower_high = list(map(int,input().split()))
good_tower = [1]*n

def check_tower(a,b):
    if tower_high[a]<tower_high[b]:
        good_tower[a]=0
    else:
        good_tower[b]=0

for i in range(m):
    a,b=list(map(int,input().split()))
    check_tower(a-1,b-1)
print(good_tower.count(1))

Submission status: Wrong Answer

Solution code:
import itertools
N , M = (map(int , input().split()))
H = list(map(int , input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
HH = {i+1 : H[i] for i in range(len(H))}
count = []
for i in AB:
    if HH[i[1]] > HH[i[0]]:
        count.append(i[1])
CC = list(set((list(itertools.chain.from_iterable(AB)))))
for i in HH:
    if i in CC:
        pass
    else:
        count.append(i)
print(len(list(set(count))))

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