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=(int(x) for x in input().split())
h=[int(x) for x in input().split()]
iiyo=[]
tmp=list(range(1, m+1))
 
for i in range(m):
    a,b=(int(x) for x in input().split())
    if a in tmp:
        tmp.remove(a)
    elif b in tmp:
        tmp.remove(b)
    else:
        if a<b:
            if b in iiyo:
                continue
            iiyo.append(b)
            if a in iiyo:
                iiyo.remove(a)
        elif a>b:
            if a in iiyo:
                continue
            iiyo.append(a)
            if b in iiyo:
                iiyo.remove(b)
        else:
            if a in iiyo:
                iiyo.remove(a)
            if b in iiyo:
                iiyo.remove(b)
 
print(len(iiyo)+len(tmp))

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

ans = []
for i in range(n):
    n_ex = []
    for j in range(m):
        ab_ex = ab[j]
        if ((i+1) in ab_ex):
            index_root = ab_ex.index(i+1)
            if (index_root == 0 and ab_ex[1] not in n_ex):
                n_ex.append(ab_ex[1]-1)
            elif (index_root == 1 and ab_ex[0] not in n_ex):
                n_ex.append(ab_ex[0]-1)
    if (len(n_ex) == 0):
        ans.append(i)
        break
    else:
        for k in range(len(n_ex)):
            if (h[i] > h[n_ex[k]] and k == (len(n_ex)-1)):
                ans.append(i)
            elif(h[i] <= h[n_ex[k]]):
                break

print(len(ans))

Submission status: Wrong Answer

Solution code:
N , M = map(int,input().split())
h = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(M):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
ans=0

newg=[]
for j in graph:
    
    newg.append(set(j))


for index,i in enumerate(newg):
    judge=0
    for j in i:
        if h[index] > h[j]:
            judge=1
        if h[index] <= h[j]:
            judge=0
            break
    if judge==1:
        ans+=1
print(ans)

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)
    
if (n-len(set(tmp))) > 0:
  good.append(n-len(set(tmp)))

print(len(set(good)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

highs = list(map(int, input().split()))
towers = list(range(n))

d = defaultdict(list)

for i in range(m):
    v = list(map(int, input().split()))
    d[v[0]].append(v[1])
    d[v[1]].append(v[0])

count = 0
for k, v in d.items():
    nums = []
    
    if towers.count(k-1) > 0:
        towers.remove(k-1)
    for i in v:
        if k < highs[i-1]:
            break
    else:
        count += 1

print(count+len(towers))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
H = list(map(int,input().split()))
ans = []
cut =[]
for i in range(m):
  a,b = map(int,input().split())
  ans.append(a)
  ans.append(b)
  if a in cut:
    cut.append(a)
  else:
    cut.append(min(a,b))
    
ansset = set(ans)
cutset = set(cut)

print(len(ansset)-len(cutset))

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):
    L = list(map(int,input().split()))
    A.append(L[0])
    B.append(L[1])

good_H = set()

for j in range(1,len(H)+1):
    print('j:',j)
    GOOD = True
        
    for i in range(M):
        if A[i] == j:
            if H[B[i]-1] >= H[j-1]:
                GOOD = False
        
        if B[i] == j:
            if H[A[i]-1] >= H[j-1]:
                GOOD = False
    
    if GOOD == True:
        good_H.add(j)

print(len(good_H))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
hight=list(map(int,input().split()))
List=[]
for i in range(m):
    a,b=map(int,input().split())
    if hight[a-1] > hight[b-1]:
        List.append(a)
        if b in List:
            List.remove(b)
    else:
        List.append(b)
        if a in List:
            List.remove(a)
print(len(set(List)))

Submission status: Wrong Answer

Solution code:
def solve():
  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
  HHNN = [[0,0] for _ in range(N)]
  for i in range(N):
    NN[i] = i
    HHNN[i][0] = i
    HHNN[i][1] = HH[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]
    HHNN[Roads[i][1]-1][0] = HHNN[Roads[i][0]-1][0]

  NN_unique = list(set(NN))
  
  HHNN.sort(key=lambda x:(x[0],x[1]), reverse= True)
  #print(HHNN)

  cnt = 0
  g = 0
  mx = 0
  for hn in HHNN:
    if g!=hn[0]:
      g=hn[0]
      mx = hn[1]
    if hn[1]==mx:
      cnt += 1
  print(cnt)
solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(1 << 25)  # 再起上限引き上げ
N, M = list(map(int, input().split()))
H = list(map(int,input().split()))
G = defaultdict(lambda: [])
# graphをdefault dictで保持することにする。
for _ in range(M):
    s, t = list(map(int, input().split()))
    s -=1
    t -=1
    G[s].append(t)
    G[t].append(s)
def dfs(node: int,color,ans):
    # 終了条件 #すでに訪問済みなら訪問しない
    if color[node] !=0:
        return ans
    # 処理
    color[node] = 1
    # 探索
    flag=0
    for n in G[node]:
        if H[n] > H[node]:
            flag=1
            break
        dfs(n,color,ans)
    if flag == 1:
        ans=0
        return ans
    return ans

# すべてのnodeを開始点としてdfsで領域わけしてみる
ans=0
for node in G.keys():
    color = [0]*N 
    ans += dfs(node,color,1)  
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    ab = [list(map(int, input().split())) for i in range(m)]
    path = [[] for i in range(n)]
    ans = 0
    for i in range(m):
        path[ab[i][0]-1].append(ab[i][1]-1)
        path[ab[i][1]-1].append(ab[i][0]-1)
    for i in path:
        if not (i):
            i.append(-1)
    for i, ele in enumerate(path):
        high = []
        for j in ele:
            high.append(h[j])
        if h[i] > max(high):
            ans += 1
    print(ans)



if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
route = []
lower = []
cnt = 0
for i in range (m):
    s = list(map(int,input().split()))
    if h[s[0]-1] >= h[s[1]-1]:
        lower.append(s[1])
    elif h[s[1]-1] >= h[s[0]-1]:
        lower.append(s[0])
low = list(set(lower))
cnt =n-len(low)
print(cnt)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
J = list()
l = [0]*N
res = 0
for i in range(M):
    j = list(map(int, input().split()))
    J.append(j)
a = 0
b = 0
for m in range(M):
    A = J[m][0] - 1
    B = J[m][1] - 1
    if H[A] >= H[B]:
        l[A] += 1
    elif H[A] <= H[B]:
        l[B] += 1

P = list()
for i in l:
    if i != 0:
        P.append(i)
print(len(P))

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np

class Graph:
    def __init__(self, n, directed=False):
        self.graph = [deque([]) for _ in range(n)]
        self.directed = directed

    def add_edge(self, u, v):
        self.graph[u].append(v)
        if not self.directed: self.graph[v].append(u)

    def bfs(self, start):
        visited = [False for _ in range(len(self.graph))]
        queue = deque([start])
        good = 0
        
        visited[start] = True
        
        while queue:
            v = queue.popleft()
            gflag = True
            # print(f'v: {v}')
            for i in self.graph[v]:
                if not visited[i]:
                    queue.append(i)
                    visited[i] = True
                    if h[v] < h[i]:
                        gflag = False
                        break
            if gflag: good += 1
        return good

if __name__ == '__main__':
    n , m = map(int, input().split())
    *h, = map(int, input().split())
    h_s = np.sort(np.array(h))[-1::-1]
    h_ind = np.argsort(h)[-1::-1]
    # print(h_s)
    # print(h_ind)
    g = Graph(n)
    # a = []
    # b = []
    # d = {}
    for _ in range(m):
        ai, bi = map(int, input().split())
        g.add_edge(ai - 1, bi - 1)
        # a.append(ai)
        # b.append(bi)
    # print(g.graph)
    ans = g.bfs(h_ind[0])
    print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A_B = [list(map(int, input().split())) for i in range(M)]
cnt = 0
for i in range(1, N+1):
    tmp_list = []
    for j in A_B:
        if i in j:
            tmp_list.append(j)
    if len(tmp_list) == 0:
        cnt+=1
    partner = sum(tmp_list, [])
    partner = [k for k in partner if k != i]
    if all([l < i for l in partner]):
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ok=np.ones(N)
for i in range(M):
    if H[A[i][0]-1]>H[A[i][1]-1]:
        ok[A[i][0]-1]=1
        ok[A[i][1]-1]=0
    elif H[A[i][0]-1]==H[A[i][1]-1]:
        ok[A[i][0]-1]=0
        ok[A[i][1]-1]=0
    else:
        ok[A[i][1]-1]=1
        ok[A[i][0]-1]=0
print(int(np.sum(ok)))

Submission status: Wrong Answer

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

ans = int(N/2)
print(ans)

Submission status: Wrong Answer

Solution code:
N , M = map(int,input().split())
h = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(M):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
ans=0

newg=[]
for j in graph:
    
    newg.append(set(j))


for index,i in enumerate(newg):
    judge=0
    for j in i:
        if h[index] >= h[j]:
            judge=1
        if h[index] < h[j]:
            judge=0
            break
    if judge==1:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
height = list(map(int,input().split()))
# print(height)
bridge = [[] for i in range(n)]

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

# print(bridge)
good = [None for i in range(n)]
# print(good)

flag = True
for i in range(n):
	flag = True
	if good[i] == None:
		# print(str(i+1)+'番目の展望台を調べます。')
		for tembo in bridge[i]:
			# print(str(tembo+1)+'番目の展望台につながっています。')
			if height[i] <= height[tembo]:
				# print(str(tembo+1)+'のほうがい高いので良くない')
				flag = False
		good[i] = flag
		if good[i]:
			for tembo in bridge[i]:
				good[tembo] = False

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

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
H=list(map(int, input().split()))
h={}
for i in range(M):
  A=list(map(int, input().split()))
  Ah = H[A[0]-1]
  Bh = H[A[1]-1]
  if Ah > Bh:
    h[A[0]] = Ah
    if A[1] in h:
      h.pop(A[1])
  else:
    h[A[1]] = Bh
    if A[0] in h:
      h.pop(A[0])
print(len(h))

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 166: C (2020/05/03)
N, M = map(int, input().split())
l = input().split()
H = [int(l[i]) for i in range(N)]
R = []
for j in range(M):
    A, B = map(int, input().split())
    if [A, B] not in R:
        R.append([A, B])
        R.append([B, A])
R = sorted(R)
ans = 0
s = 0
flag = 1
for k in range(len(R)):
    if s != R[k][0]:
        if flag == 1 and s != 0:
            ans = ans + 1
        if R[k][0] - s > 1:
            ans = ans + R[k][0] - s - 1
        s = R[k][0]
        flag = 1
        if H[R[k][0]-1] > H[R[k][1]-1]:
            flag = flag * 1
        else:
            flag = flag * 0
    else:
        if H[R[k][0]-1] > H[R[k][1]-1]:
            flag = flag * 1
        else:
            flag = flag * 0
if flag == 1:
    ans = ans + 1
print(ans)

Submission status: Wrong Answer

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

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

lose_l = []
while M > 0:
    a,b = map(int, input().split())
    if h_l[a-1] > h_l[b-1]:
        lose_l.append(h_l[b-1])
    if h_l[a-1] < h_l[b-1]:
        lose_l.append(h_l[a-1])
    else:
        lose_l.append(h_l[a-1])
        lose_l.append(h_l[b-1])
    M -= 1

result = list(set(h_l) - set(lose_l))
print(len(result))

Submission status: Wrong Answer

Solution code:
import collections
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = [1]*N
for i in range(M):
    a = list(map(int, input().split()))
    if H[a[1]-1]>H[a[0]-1]:
        B[a[0]-1] = -1
        if B[a[1]-1]==1:
            B[a[1]-1]=2
    elif H[a[1]-1]<H[a[0]-1]:
        B[a[1]-1]=-1
        if B[a[0]-1]==1:
            B[a[0]-1]=2
    elif H[a[1]-1]==H[a[0]-1]:
        if B[a[1]-1]==-1 or B[a[0]-1]==-1:
            B[a[0]-1]=-1
            B[a[1]-1]=-1
        else:
            A.append(a)
#print(A)
if len(A)>=1:
    for i in range(len(A)):
        if B[A[i][0]-1]==-1 or B[A[i][1]-1]==-1:
            B[A[i][0]-1]=-1
            B[A[i][1]-1]=-1
#print(B)
c = collections.Counter(B)
print(c[1]+c[2])

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)
        if (flag == 1):
            flag=0

    print(cnt)


road()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ok=np.ones(N)
for i in range(M):
    if H[A[i][0]-1]>H[A[i][1]-1]:
        ok[A[i][0]-1]=1
        ok[A[i][1]-1]=0
    elif H[A[i][0]-1]==H[A[i][1]-1]:
        ok[A[i][0]-1]=0
        ok[A[i][1]-1]=0
    else:
        ok[A[i][1]-1]=1
        ok[A[i][0]-1]=0
    print(ok)
print(int(np.sum(ok)))

Submission status: Wrong Answer

Solution code:
import sys

lines = sys.stdin.readlines()

X = lines[0].split(' ')
N = int(X[0])
M = int(X[1])

H = []
Y = [0 for j in range(N)]
Z =[0]*N

for i in range(N):
    H.append(lines[1].split(' ')[i])

for j in range(M):
    A = int(lines[j+2].split(' ')[0])
    B = int(lines[j+2].split(' ')[1])
    if Y[A-1] < int(H[B-1]):
      Y[A-1] = int(H[B-1])
    if Y[B-1] < int(H[A-1]):
      Y[B-1] = int(H[A-1])

print(1)

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 i in range(m)]

#H[i] # iの高さ

# 隣接行列
road_close = [0]*n

for i in range(len(road)):
    # idx=int(road[i][0])-1
    # print(idx)
    # print(road_close[idx])

    if road_close[road[i][0]-1]!=0:
        road_close[road[i][0]-1].append(road[i][1])
    else:
        list = [(road[i][1])]
        road_close[road[i][0]-1]=list

    if road_close[road[i][1]-1] != 0:
        road_close[road[i][1]-1].append(road[i][0])
    else:
        list = [(road[i][0])]
        road_close[road[i][1]-1]=list


count=[]
idx=0
for r in road_close:
    if r==0:
        continue
    for i in r:
        if H[idx] > H[i-1]:
            count.append(idx)
    idx+=1
print(len(set(count)))

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

    f=0
    z=0
    for h in ls:
        if ls.count(h)>1:
            z=1
            break
        if hill[k-1]<hill[h-1]:
            f=1
            break
    if z:
        continue
    if not f:
      #  print(k)
        ans+=1  
#print(ans)
ans+=(N-len(dc.keys()))
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
cnt = 0
for i in range(M):
  a, b = map(int, input().split())
  ab = sorted([a, b])
  if AB.count(ab) == 0:
    AB.append(ab)

for i in range(1, N+1):
  flag = True
  for ab in AB:
    if ab[0] == i:
      x = ab[1]
      if H[i - 1] <= H[x - 1]:
        flag = False
        AB.remove(ab)
        break
    elif ab[1] == i:
      x = ab[0]
      if H[i - 1] <= H[x - 1]:
        flag = False
        break
  if flag:
    cnt += 1
      
print(cnt)

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 i in range(m)]

resList = []
for i in range(m):

    if(h_[a_[i][0] -1] > h_[a_[i][1] -1]):
        res = a_[i][0]
        res_not = a_[i][1]
    elif(h_[a_[i][0] -1] < h_[a_[i][1] -1]):
        res = a_[i][1]
        res_not = a_[i][0]
    else:
        continue

    if(res in resList):
        continue
    else:
        resList.append(res)

    if(res_not in resList):
        resList.remove(res_not)
    else:
        continue

print(len(resList))

Submission status: Wrong Answer

Solution code:
import os

def main():
	n,m = map(int, input().split())
	h_list = list(map(int, input().split()))
	ans = [1]*n
	result = []
	for i in range(m):
		a,b = map(int, input().split())
		if h_list[a-1] < h_list[b-1]:
			ans[a-1] = 0	
		else:
			ans[b-1] = 0
	print(sum(ans))			

if __name__ == "__main__":
	main()

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)
L = [[] for i in range(n+1)]
ans = []
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()))

ans = set([i for i in range(n)])

for i in range(m):
    a, b = map(int,input().split())
    a -= 1; b -= 1
    if h[a] <= h[b]:
        ans = ans - {a}
    elif h[b] <= h[a]:
        ans = ans - {b}

print(len(ans))

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

    graph = [[] for _1 in range(N)]
    for a,b in AB:
        graph[a-1].append(b)
        graph[b-1].append(a)
    ans = 0

    for i in range(N):
        height = H[i-1]
        for j in graph[i]:
            if height <= H[j-1]:
                break
        else:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N , M = map(int,input().split())
h = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(M):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
ans=0

newg=[]
for j in graph:
    
    newg.append(set(j))


for index,i in enumerate(newg):
    judge=0
    for j in i:
        print(index , j,ans)
        if h[index] >= h[j]:
            judge=1
        if h[index] < h[j]:
            judge=0
            break
    if judge==1:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

height_map = {}

for index, height in enumerate(H):
    height_map[index] = height


yoi_tenbou_map = defaultdict(list)

for _ in range(M):
    node_one, node_two = map(int, input().split())
    yoi_tenbou_map[node_one].append(node_two)

result_count = 0

toutatsu_node_list = []

for key in yoi_tenbou_map.keys():
    nodes = yoi_tenbou_map[key]
    nodes.append(key)
    height_array = []
    for node in nodes:
        height_array.append(height_map[node - 1])
    sorted_height_array = sorted(height_array, reverse=True)
    if (sorted_height_array[0] != sorted_height_array[1]):
        result_count += 1

    toutatsu_node_list.append(key)
    toutatsu_node_list.extend(yoi_tenbou_map[key])

dokuritsu_node_count = N - len(set(toutatsu_node_list))

print(result_count + dokuritsu_node_count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

d = defaultdict(list)

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

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

for i in range(M):
    a, b = list(map(int, input().split()))
    d[a-1].append(b-1)
    d[b-1].append(a-1)

ans = 0
for i in range(N):
    ng = 0

    if(i not in d):
        ans += 1
        break

    for j in d[i]:
        if(H[i] <= H[j]): ng = 1
    if(ng != 1):
        ans += 1

print(ans)

Submission status: Wrong Answer

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

for i in range(m):
    flag=0
    a,b=map(int,input().split())

    if l[a-1] > l[b-1]:
        continue
    elif l[a-1] == l[b-1]:
        tmp[a-1]=-1
        tmp[b-1]=-1
    else:
        flag=1
    if flag==0:
        if tmp[a-1]!= -1:
            tmp[a-1] += 1
        tmp[b-1]=-1
    if flag==1:
        if tmp[b-1]!= -1:
            tmp[b-1] += 1
        tmp[a-1]=-1

cnt=0
for i in range(len(tmp)):
    if tmp[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 = [list(map(int, input().split())) for i in range(M)]

cnt = 0

s = set()
used = set()
for i in range(M):
    lef = AB[i][0]-1
    rig = AB[i][1]-1
    if not H[lef] == H[rig]:
        s.add(max(H[lef], H[rig]))
        used.add(H[lef])
        used.add(H[rig])

cnt = len(set(H)) - len(used)
print(len(s)+cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n, m = map(int, sys.stdin.readline().split())
li = list(map(int, sys.stdin.readline().split()))
li2 = ['a']*n
for _ in range(m):
  i, k = map(int, sys.stdin.readline().split())
  k -= 1
  i -= 1
  if li[k] - li[i] >= 0:
    if li2[k] != 'F':
      li2[k] = 'T'
    li2[i] = 'F'
  else:
    if li2[i] != 'F':
      li2[i] = 'T'
    li2[k] = 'F'
print(li2.count('T'))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
H = list(map(int,input().split()))
count = 0
for _ in range(M):
    A, B = map(int,input().split())
    if H[B-1] < H[A-1]:
        count +=1
    if H[B-1] > H[A-1]:
        count +=1
print(count)

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])
pathway = eval(inputs[0].split(" ")[1])
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:
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]
print(len(set(cell)))

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

	print(ans)





if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-05-03 21:27:46 +0900
# LastModified: 2020-05-03 22:10:55 +0900
#


import os
import sys


def main():
    n,m = map(int,input().split())
    h = list(map(int,input().split()))
    color=[0]*n
    matrix = list([0]*n for _ in range(n))
    for i in range(m):
        a,b = map(int,input().split())
        matrix[a-1][b-1]=1
        matrix[b-1][a-1]=1

    count=0
    for i in range(n):
        flag=0
        for j in range(n):
            if matrix[i][j]==1 and h[i]<=h[j] and color[j]!=1:
                flag=1
                break
        if flag==0:
            color[i]=1
            count+=1
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy
n,m=map(int,input().split())
h=[0]+list(map(int,input().split()))
hh=copy.copy(h)
for i in range(m):
  a,b=map(int,input().split())
  if h[a]>h[b]:
    h[b]=h[a]
  elif h[a]<h[b]:
    h[a]=h[b]
cnt=0
for j in range(1,n+1):
  if h[j]==hh[j]:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
p = []
lst = list(map(int, input().split()))
lst1 = [input().split() for _ in range(m)]
for i in range(m):
    p.append(max(lst1[i][0],lst1[i][1]))
print(len(set(p)))