Problem:


Score : 300 points

Problem Statement

There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.
There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.

Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.
Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.

How many good observatories are there?

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq H_i \leq 10^9

1 \leq A_i,B_i \leq N

A_i \neq B_i

Multiple roads may connect the same pair of observatories.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Print the number of good observatories.

Sample Input 1

4 3
1 2 3 4
1 3
2 3
2 4

Sample Output 1

2

From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.

From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.

From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.

From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.

Thus, the good observatories are Obs. 3 and 4, so there are two good observatories.

Sample Input 2

6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6

Sample Output 2

3



Sample input:
4 3
1 2 3 4
1 3
2 3
2 4


Sample output:
2

Submission status: Wrong Answer

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

H = input().split()
if (M > 0):
  # N本分入る．
  arr = []
  for i in range(M):
    A, B = map(int, input().split())
    if int(H[A-1]) > int(H[B-1]):
      arr.append(H[A-1])
    else:
      arr.append(H[B-1])

  print(len(list(set(arr))))
else:
  print(H[len(H)-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int,input().split())
H = np.array([0] + list(map(int,input().split())))
A , B = [0]*M,[0]*M
for i in range(M):
    A[i],B[i] = map(int,input().split())
adj = [[] for _ in range(N+1)]

for a,b in zip(A,B):
    adj[a] += [b]
    adj[b] += [a]

# stack = [1]
# while stack:
#     node = stack.pop()
#     l = adj[node]
#     cand = np.argmax(H[node,l])
cache = [0]
ans = 0
for i in range(1,N+1):
    if i in cache:
        continue
    ind = np.array([i] + adj[i])
    cand = np.argsort(H[ind])[::-1]
    cand = ind[cand]
    if i == cand[0]:
        ans +=1
    cache=np.concatenate((cache,cand[1:]),axis=None)
print(ans)

Submission status: Wrong Answer

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

o_height = input().split()
result = []
for i in range(N):
    result.append(True)

while(M):
    road = input().split()
    if int(o_height[int(road[0])-1]) < int(o_height[int(road[1])-1]):
        result[int(road[0])-1] = False
    else:
        result[int(road[1])-1] = False
    M-=1

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

Submission status: Wrong Answer

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





NG_list = []

for i in range(M):
    if(H_list[A_list[i]-1]<H_list[B_list[i]-1]):
        NG_list.append(A_list[i])
    elif(H_list[A_list[i]-1]==H_list[B_list[i]-1]):
        NG_list.append(A_list[i])
        NG_list.append(B_list[i])
#print(NG_list)
NG_list = set(NG_list)
NG_list = list(NG_list)

print(N-len(NG_list))

Submission status: Wrong Answer

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

no_good = []
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    a -= 1
    b -= 1
    if H[a] < H[b]:
        no_good.append(a)
    else:
        no_good.append(b)
print(N - len(set(no_good)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [0] * (m+1)
ab = [0] * m * 2
for i in range(m):
    ai, bi = map(int, input().split()) 
    ab[i] = ai
    ab[i+m] = bi
    if h[ai-1] > h[bi-1]:
        ans[i] = ai
        if bi in ans:
            ans[ans.index(bi)] = 0
    elif h[ai-1] < h[bi-1]:
        ans[i] = bi
        if ai in ans:
            ans[ans.index(ai)] = 0
t = n - len(list(set(ab)))
print(len(set(ans))-1 + t)

Submission status: Wrong Answer

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n, m = map(int, input().split())
  h = list(map(int, input().split()))
  ab = [list(map(int, input().split())) for _ in range(m)]
  L = [0] * n

  for i in range(m):
      A =ab[i][0]-1
      B =ab[i][1]-1
      M = max(h[A],h[B])
      if M == h[A]:
          L[A] += 0.33
          L[B] -= 100
      else: 
          L[B] += 0.33
          L[A] -= 100
      
  L= list(filter(lambda x: x >= 0, L))
  print(len(L))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

print(sum(ten))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
s = list(map(int, input().split()))
#print(s)
P = [input().split() for i in range(M)]
#print(P)
ans = 0
for i in range(N):
    good = []
    for j in range(len(P)):
        #print(P[j][0])
        #print(i+1)
        if int(P[j][0]) == i+1:
            good.append(s[int(P[j][1])-1])
        if int(P[j][1]) == i+1:
            good.append(s[int(P[j][0])-1])
    #print(good)
    if len(good)>0:
        if s[i-1] > max(good):
            ans = ans+1
    else:
        ans= ans+1
print(ans)

Submission status: Wrong Answer

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

ansdic = {}

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if Hlist[a] < Hlist[b]:
        ansdic[Hlist[b]] = True
        ansdic[Hlist[a]] = False

ans = 0

for h in Hlist:
    if h in ansdic:
        if ansdic[h]:
            ans += 1
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
NM = list(map(int, input().split()))
N=NM[0]
M=NM[1]
H = list(map(int, input().split()))
AB_list = []
for i in range(M):
  AB = list(map(int, input().split()))
  AB_list.append(AB)
  
good = []
queue = list(range(1,N+1))
while queue:
  n = queue.pop()
  hi = H[n-1]
  i = n+1
  reachable = list(set(sum([x for x in AB_list if i in x],[])))
  if not reachable:
    good.append(i)
    continue
  reachable.remove(i)
  reachable_hi = [H[x-1] for x in reachable]
  if max(reachable_hi) < hi:
    good.append(i)
    queue = list(set(queue)-set(reachable))
print(len(good))

Submission status: Wrong Answer

Solution code:
def main():
    n,m = map(int, input().split())
    H = list(map(int,input().split()))
    # array = [list(map(int,input().split())) for _ in range(m)]
    pool = set(range(1, n+1))

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

    print(len(pool))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
l=list()
for i in range(M):
  A,B=map(int,input().split())
  if H[A-1]==H[B-1]:
    l.append('a')
  else:
    bad=(min(H[A-1],H[B-1]))
    l.append(bad)
  
minus=(len(set(l)))
h=len(H)
print(h-minus)

Submission status: Wrong Answer

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





NG_list = []

for i in range(M):
    if(H_list[A_list[i]-1]<H_list[B_list[i]-1]):
        NG_list.append(A_list[i])
    elif(H_list[A_list[i]-1]==H_list[B_list[i]-1]):
        NG_list.append(A_list[i])
        NG_list.append(B_list[i])
print(NG_list)
NG_list = set(NG_list)
NG_list = list(NG_list)

print(N-len(NG_list))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
ans=0
A=[0]*N
path=[]
for i in range(M):
    a,b=map(int,input().split())
    path.append(a)
    path.append(b)
    if H[a-1]>H[b-1]:
        if A[a-1]==-1:
            pass
        else:
            A[a-1]=1
    elif H[b-1]>H[a-1]:
        if A[b-1]==-1:
            pass
        else:
            A[b-1]=1
    else:
        pass
print(A.count(1)+N-len(set(path)))

Submission status: Wrong Answer

Solution code:
from math import factorial
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
good = []
tmp = []

for i in range(m):
  a,b = map(int,input().split())
  
  tmp.append(a)
  tmp.append(b)
  a_num = h[a-1]
  b_num = h[b-1]
  if a_num > b_num:
    good.append(a)
  elif b_num > a_num:
    good.append(b)

result = len(set(good))

if (n-len(set(tmp))) > 0:
  result += n-len(set(tmp))
  
print(result)

Submission status: Wrong Answer

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

dp=[True]*N
a=[0]*N

for i in A:
  if H[i[0]-1]<H[i[1]-1] and a[i[1]-1]==0:
    dp[i[1]-1]=True
    dp[i[0]-1]=False
    a[i[0]-1]+=0
  elif H[i[0]-1]<H[i[1]-1] and a[i[1]-1]!=0:
    dp[i[1]-1]=False
    dp[i[0]-1]=False
    a[i[0]-1]+=0
    continue
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]==0:
    dp[i[1]-1]=False
    dp[i[0]-1]=True
    a[i[1]-1]+=0
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]!=0:
    dp[i[1]-1]=False
    dp[i[0]-1]=False
    a[i[1]-1]+=0
    continue
  elif H[i[0]-1]==H[i[1]-1]:
    dp[i[1]-1]=False
    dp[i[0]-1]=False
  

print(dp.count(True))

Submission status: Wrong Answer

Solution code:
import collections
N,M=map(int,input().split())
H=input().split()
tenboudai=[i for i in range(1,N+1)]
lose=[]
for i in range(M):
    X=input().split()
    A=int(X[0])
    B=int(X[1])
    if H[A-1]>=H[B-1]:
        lose.append(B)
    elif H[A-1]<=H[B-1]:
        lose.append(A)
    
a=len(tenboudai)
b=len(collections.Counter(lose))

print(a-b)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = []
good = 0
for i in range(m):
    a = list(map(int, input().split()))
    l.extend(a)

for i in range(1, n+1):
    a = [j for j, x in enumerate(l) if x == i]

    if a==[]:
        good += 1
        continue
    for j in a:
        if j%2==0:
            if (h[l[j+1]-1]<h[l[j]-1]):
                g = 1
            else:
                g = 0
        else:
            if (h[l[j-1]-1]<h[l[j]-1]):
                g = 1
            else:
                g = 0
    if g==1:
        good += 1

print(good)

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())
cnt = 0

for j in range(N):
    for k in range(M):
        if A[k] == j+1 and H[B[k]-1] > H[A[k]-1]:
            cnt += 0
        elif B[k] == j+1 and H[B[k]-1] < H[A[k]-1]:
            cnt += 0
        elif A[k] == j+1 or B[k] == j+1:
            print(A[k])
            print(B[k])
            cnt += 1

print(cnt)

Submission status: Wrong Answer

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

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

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

print(N-sum(par))

Submission status: Wrong Answer

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

    cnt = [0]*n
    for i in range(n):
        l = []
        for j in range(len(ab)):
            a, b = ab[j]
            if a == i+1:
                if h[i] <= h[b-1]:
                    cnt[i] -= 1
                else:
                    l.append([a, b])
            elif b == i+1:
                if h[i] <= h[a-1]:
                    cnt[i] -= 1
                else:
                    l.append([a, b])
        for k in range(len(l)):
            ab.remove(l[k])       

    
    return cnt.count(0)




print(solve())

Submission status: Wrong Answer

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

for i in range(M):
    a,b = map(int,input().split())
    if H[a-1] != H[b-1]:
        if H.index(min(H[a-1],H[b-1])) in ans:
            ans.remove(H.index(min(H[a-1],H[b-1])))
    else:
        if a-1 in ans or b-1 in ans:
            if a-1 in ans:
                ans.remove(a-1)
            else:
                ans.remove(b-1)
        
print(len(ans))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ans=[]
ans=list(map(int,input().split()))
count=0
#di=defaultdict(list)
ma=[]
for i in range(m):
    a,b=map(int,input().split())
    if ans[a-1]>=ans[b-1] and ans[a-1] not in ma:
        count+=1
        ma.append(ans[a-1])
    if ans[b-1]>=ans[a-1] and ans[b-1] not in ma:
        count+=1
        ma.append(ans[b-1])
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
Hs = input().split()
Hs = [int(ele) for ele in Hs]

res = [1 for i in range(n) ]
for i in range(m):
    con = input().split()
    con = [int(ele) for ele in con]
    con.sort()
    # id1 < id2となっている
    id1 = con[0] - 1
    id2 = con[1] - 1
    
    if Hs[id2] == Hs[id1]:
        res[id1] = 0
        res[id2] = 0
    else:    
        res[id1] = (Hs[id2] - Hs[id1] < 0)
        res[id2] = (Hs[id1] - Hs[id2] < 0)

ans = sum(res)

print(ans)

Submission status: Wrong Answer

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

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
temp=input()
obs, rds = map(int, temp.split())
obs_h = list(map(int, input().split()))
i=0
cal = []
for i in range(len(obs_h)):
    cal.append({})
i=0
while i<rds:
    s, e = map(int, input().split())
    if e-1 in cal[s-1]:
        cal[s-1][e-1] += 1
    else:
        cal[s-1][e-1]=1
    if s-1 in cal[e-1]:
        cal[e-1][s-1] += 1
    else:
        cal[e-1][s-1]=1
    i += 1
cnt=0
for i in range(len(cal)):
    if len(cal[i]) == 0:
        cnt += 1
        continue
    check = -1
    good=0
    for j in cal[i]:
        # check = 1
        if cal[i][j] == 1:
            
            if obs_h[i] > obs_h[j]:
                good = 1
            else:
                good = -1
                break
    # print(i, good)
    if not good == -1:
        # print(i)
        cnt += 1
print(cnt)
# print(cal)       

'''

6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6

'''

Submission status: Wrong Answer

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

print(x)

Submission status: Wrong Answer

Solution code:
from collections import deque


N, M = map(int, input().split())
hight = list(input().split())
hight = [int(hight[i]) for i in range(N)]

G = [deque([]) for i in range(N+1)] 

road = [input().split() for i in range(M)]

for i in range(M):
    G[int(road[i][0])].append(int(road[i][1]))
    G[int(road[i][1]) - 1].append(int(road[i][0]))    
    
count = 0

def dfs(v, num):
    while v:    
        tmp = v.pop()
        if hight[tmp - 1] > hight[num - 1]:
            return False
        else:
            continue
    
    return True
  
for i in range(N):
    if dfs(G[i+1], i+1):
        count += 1
    else:
        continue

print(count)

Submission status: Wrong Answer

Solution code:
def road():
    n, m = map(int, input().split())
    high = list(map(int, input().split()))
    node = [0]*(m*2)
    cnt = 0
    good = []

    for i in range(0, 2*m-1, 2):
        node[i], node[i+1] = map(int, input().split())

    for j in range(1, n+1):
        if j not in node:
            cnt += 1
            good.append(j)

    for i in range(0, n):
        if high[i]==max(high):
            good.append(i+1)
            cnt+=1

    flag = 0
    for k in range(1, n+1):
        for i in range(0, 2*m):
            if node[i]==k:
                if  i%2==0 and high[k-1]<=high[node[i+1]-1]:
                    flag = 1
                    break
                if  i%2==1 and high[k-1]<=high[node[i-1]-1]:
                    flag = 1
                    break
        if (flag==0) and (k not in good):
            cnt+=1
            good.append(k)
        flag = 0

    print(cnt)


road()

Submission status: Wrong Answer

Solution code:
import numpy as np

inputs = []
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

obsv = eval(inputs[0].split(" ")[0])
heights = [eval(a) for a in inputs[1].split(" ")]
ways = sorted(set(inputs[2:]))
ways = [[eval(b) for b in a.split(" ")] for a in ways]
no_conn = obsv - len(sorted(set(sum(ways, []))))

ways_inv = [[j,i] for [i,j] in ways]
ways.extend(ways_inv)
ways = sorted(ways)

count = no_conn
start = 1
is_good = []
for w in ways:
  is_good.append(heights[start-1] > heights[w[1]-1])
  if start != w[0]:
    if np.all(is_good):
        count += 1
    start = w[0]
    is_good = []
if np.all(is_good):
  count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
H = list(map(int, input().split()))
adj = defaultdict(lambda : {0})
for i in range(M):
    a, b = map(int, input().split())
    adj[a-1].add(H[b-1])
    adj[b-1].add(H[a-1])
ans = 0
for i in range(N):
    if H[i] > max(adj[H[i]]):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
table = [[-1 for _ in range(N)] for _ in range(N)]
H = map(int,input().split())
high = [h for h in H] 
 
for m in range(M):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    high_a = high[a]
    high_b = high[b]
    if high_a > high_b:
        table[a][b] = 1
        table[b][a] = 0
    else:
        table[b][a] = 1
        table[a][b] = 0
        
 
cnt = 0
for n in range(N):
    table_ = table[n]
    if(not any([t==0 for t in table_]) and not all([t==-1 for t in table_])):
        cnt +=1
    
print(cnt)

Submission status: Wrong Answer

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

H = list(map(int,input().split()))
T = [True]*n
A=[0]*m
B=[0]*m
for i in range(m):
    A[i],B[i] = map(int,input().split())

box=[[0] for _ in range(n)]
for i in range(m):
    if H[A[i] -1] - H[B[i] -1] < 0:
        box[A[i] -1].append(1)
        box[B[i] -1].append(0)
        
    elif H[A[i] -1] - H[B[i] -1]==0:
        box[A[i] -1].append(1)
        box[B[i] -1].append(1)
        
for i in range(n):
    if sum(box[i])==0:
        T[i] =True
    else:
        T[i] = False

print(T.count(True))

Submission status: Wrong Answer

Solution code:
def main():
    N, M = (int(x) for x in input().split())
    H = [int(x) for x in input().split()]
    AB = []
    for _ in range(M):
        AB.append(tuple(int(x) for x in input().split()))
    ans = 0

    for i in range(1, N+1):
        for t in AB:
            if t[0] == i:
                k = t[1]
            elif t[1] == i:
                k = t[0]
            else:
                k = None

            if k is not None:
                if H[i-1] > H[k - 1]:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,k=[int(x) for x in input().split()]
obs=[int(x) for x in input().split()]
ans=set(obs)
answer=set()
fake=set()
for i in range(0,k):
    a,b=[int(x) for x in input().split()]
    fake.add(a)
    fake.add(b)
    if b>a:
       answer.add(b)

    elif a>b:
        if b in answer:
          answer.remove(b)

ans=ans-fake
print(len(ans.union(answer)))

Submission status: Wrong Answer

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

tmp = [0] * N

AB = [map(int, input().split()) for _ in range(M)]
A, B = [list(i) for i in zip(*AB)]      
    
for i in range(M):
  if H[A[i]-1] > H[B[i]-1]:
    tmp[A[i]-1] = 1
  else:
    tmp[B[i]-1] = 1
      
tmp[H.index(max(H))] = 1
print(sum(tmp))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
AB=(map(int,input().split()) for _ in range(M))
A,B=(list(i) for i in zip(*AB))
import numpy as np
C=np.ones(N)
d=0
def m(a,b):
  if H[b-1]>H[a-1]:
    return [a,a]
  if H[a-1]>H[b-1]:
    return [b,b]
  if H[b-1]==H[a-1]:
    return [a,b]
for i in range(M):
  C[m(A[i],B[i])[0]-1]=0
  C[m(A[i],B[i])[1]-1]=0
for j in range(N):
  d=d+C[j]
print(C)
print(int(d))

Submission status: Wrong Answer

Solution code:
N, M = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]
ans = [0]*N
for i in range(M):
    AB = tuple([int(n) for n in input().split()])
    if H[AB[0]-1] == H[AB[1]-1]:
        ans[AB[0]-1] = -1
        ans[AB[1]-1] = -1
    elif H[AB[0]-1] > H[AB[1]-1]:
        ans[AB[0]-1] = 1
        ans[AB[1]-1] = -1
    else:
        ans[AB[0]-1] = -1
        ans[AB[1]-1] = 1
print(ans.count(0)+ans.count(1))

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

z = set(zip(a,b))

lis = [i for i in range(1,n+1)]
cnt = n

for i,j in z:
    if h[i-1] > h[j-1]:
        if j in lis:
            lis.remove(j)
            cnt -= 1
    elif h[j-1] > h[i-1]:
        if i in lis:
            lis.remove(i)
            cnt -= 1
    else:
        if j in lis:
            lis.remove(j)
            cnt -= 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, M = map(int, input().split())
H = list(map(int, input().split()))
lst = [list(map(int, input().split())) for _ in range(M)]
# print(N, M)
# print("H",H)
# print("lst",lst)
lst2 = [[] for i in range(N)]
# print(lst2)
for j in range(M):
    for i in range(N):
        if i+1 in lst[j]:
            if lst[j][0] == i+1:
                lst2[i].append(lst[j][1])
            else:
                lst2[i].append(lst[j][0])
        # print("H[i]", H[i], "lst[i]", lst[j])
# print("lst2:", lst2)
num = N
for i in range(N):
    lst2[i].sort()
    if len(lst2[i]) == 0:
        continue
    # print(max(lst2[i]))
    if H[i] <= H[max(lst2[i])-1]:
        num -= 1
print(num)

Submission status: Wrong Answer

Solution code:
n,m = input().split()
height = list(input().split())
list = []
for i in range(1,int(n)+1):
    list.append(i)
for i in range(int(m)):
    a,b = input().split()
    a = int(a)
    b = int(b)
    if int(height[a-1]) < int(height[b-1]):
        if int(a) in list:
            list.remove(a)
    elif int(height[a-1]) > int(height[b-1]):
        if int(b) in list:
            list.remove(b)
    elif int(height[a-1]) == int(height[b-1]):
        if int(b) in list:
            list.remove(b)
        elif int(a) in list:
            list.remove(a)
print(len(list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
road=[]
for i in range(m):
    road.append(list(map(int,input().split())))
tall=[1 for _ in range(n)]
for i in range(m):
    if h[road[i][0]-1]>=h[road[i][1]-1]:
        tall[road[i][1]-1]=0
    elif h[road[i][0]-1]<=h[road[i][1]-1]:
        tall[road[i][0]-1]=0
counter=0
for i in range(n):
    if tall[i] == 1:
        counter+=1
print(counter)

Submission status: Wrong Answer

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

H=[True]*n
s=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    if A[a-1]>=A[b-1]:
        H[b-1]=False
    elif A[a-1]<=A[b-1]:
        H[a-1]=False

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [tuple(list(map(int, input().split()))) for i in range(M)]
good = []
A = [ab[0] for ab in AB]
B = [ab[1] for ab in AB]

for obj  in range(1, N+1):
    if obj in A or obj in B:
        rel = list(filter(lambda ab: ab[0]==obj or ab[1]==obj, AB))
        is_good = False
        for ablis in rel:
            a = ablis[0]
            b = ablis[1]
            if a == obj:
                if H[obj-1] > H[b-1]:
                    is_good = True
                else:
                    is_good = False
            if b == obj:
                if H[obj-1] > H[a-1]:
                    is_good = True
                else:
                    is_good = False
        if is_good:
            good.append(obj)
    else:
        good.append(obj)



print(len(set(good)))

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
hlis = list(map(int, input().split()))
road = []
for i in range(m):
    a, b = map(int, input().split())
    road.append([a, b])
table = [0]*n
ans = 0
for i in range(n):
    if table[i] == 0:
        rival = []
        for j in road:
            if j[0] == i+1:
                rival.append(j[1]-1)
            elif j[1] == i+1:
                rival.append(j[0]-1)
        if hlis[i] == max([hlis[q] for q in rival]+[hlis[i]]) and [hlis[q] for q in rival].count(hlis[i])== 0:
            table[i] = 1
            ans += 1
            for q in rival:
                table[q] = -1 
        else:
            table[i] = -1
print(ans, table)

Submission status: Wrong Answer

Solution code:
import copy
n, m = map(int, input().split())
h = [int(x) for x in input().split()]
H = copy.copy(h)
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] < h[b-1]:
        try:
            H.remove(h[a-1])
        except ValueError as e:
            pass
    if h[a-1] > h[b-1]:
        try:
            H.remove(h[b-1])
        except ValueError as e:
            pass
print(len(H))

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
H=list(map(int, input().split()))
michi=[list(map(int, input().split())) for _ in range(M) ]
shortcut=[]
hikaku=[]
peak=0
ans=0

for i in range(M):
	shortcut.append(michi[i][0])
	shortcut.append(michi[i][1])
shortcut=set(shortcut)

for i in range(1,N+1):
	if i in shortcut:
		for h in range(M):
			if michi[h][0]==i or michi[h][1]==i:
				peak=H[i-1]
				hikaku.append(H[michi[h][0]-1])
				hikaku.append(H[michi[h][1]-1])
				print(hikaku,peak)

		
		if peak==max(hikaku):
			ans+=1

		peak=0
		hikaku=[]
			
	else:
		ans+=1
	
			
print(ans)

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)]
# print(N, M, H, AB)


dictionary = {}
for A, B in AB:
    if dictionary.get(A) is None:
        dictionary[A] = []
    if dictionary.get(B) is None:
        dictionary[B] = []

    dictionary[A].append(H[B - 1])
    dictionary[B].append(H[A - 1])
# print(dictionary)

count = 0
for i, heights in dictionary.items():
    # print(i, type(i), H[i - 1], heights)
    if H[i - 1] > max(heights):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split(" "))
towers = list(map(int, input().split(" ")))
roads = []
for i in range(m):
    roads.append(list(map(int, input().split(" "))))
total = 0
for i in range(n):
    for j in range(m):
        if i + 1 in roads[j]:
            if towers[i] == max([towers[roads[j][0] - 1], towers[roads[j][1] -1]]):
                continue
            else:
                break
    else:
        total += 1
print(total)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
n = a[0]
m = a[1]

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

mem = list(range(1,n+1))

for i in range(m):
  ab = list(map(int,input().split()))
  
  if (h[ab[0]-1]>h[ab[1]-1])and(ab[1] in mem):
    mem.remove(ab[1])
      
  elif (h[ab[0]-1]<h[ab[1]-1])and(ab[0] in mem):
    mem.remove(ab[0])
  else:
    if ab[0] in mem:
      mem.remove(ab[0])
    elif ab[1] in mem:
      mem.remove(ab[1])


print(len(mem))

Submission status: Wrong Answer

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

	ans = int(n)
	del_list = set()
	for i in range(m):
		if h[l[i][0]-1] > h[l[i][1]-1] and l[i][1] not in del_list:
			ans -= 1
			del_list.add(l[i][1])
		elif h[l[i][0]-1] < h[l[i][1]-1] and l[i][0] not in del_list:
			ans -= 1
			del_list.add(l[i][0])
		elif h[l[i][0]-1] == h[l[i][1]-1]:
			if l[i][0] not in del_list:
				ans -= 1
				del_list.add(l[i][0])
			elif l[i][1] not in del_list:
				ans -= 1
				del_list.add(l[i][1])
			else:
				ans += 0
		else:
			ans += 0

	print(ans)





if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
li1 = list(map(int,input().split()))
li2 = [0]*n
for i in range(n):
    li2[i] += i+1
grid = []
S = []
S1 = [0]*2*m
for i in range(m):
    array = list(map(int, input().strip().split()))
    grid.append(array)
for i in range(m):
    if li1[grid[i][0]-1] > li1[grid[i][1]-1]:
        S.append(grid[i][0])
    if li1[grid[i][0]-1] < li1[grid[i][1]-1]:
        S.append(grid[i][1])
for i in range(m):
    S1[i] += grid[i][0]
    S1[i+m] += grid[i][1]
diff = set(S1) ^ set(li2)
print(len(list(set(S))) + len(diff))