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 = list(map(int, input().split()))
ans = [1] * n
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if h[a] < h[b]:
        ans[a] = 0
    else:
        ans[b] = 0

print(sum(ans))

Submission status: Wrong Answer

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

li = [1 for i in range(N)]

for i in range(M):
    a,b = map(int,input().split())
    a-=1
    b-=1

    if H[a]>=H[b]:
        li[b]=0
    elif H[a]<=H[b]:
        li[a]=0
# print(li)
ans = 0
for i in range(N):
    if li[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n , m = map(int , input().split())
h  = list(map(int , input().split()))
dic = defaultdict(list)
for i in range(m):
	u , v = map(int , input().split())
	dic[u].append(v)
	dic[v].append(u)
ans = 0
for i in range(1, n+1):
	currh = h[i-1]
	f = 1
	if i in dic: 
		for obs in dic[i]:
			if i == obs: continue
			if h[obs-1] > currh:
				f = 0
				break
		if f:
			ans+=1
	else:
		ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m = map(int, input().split())
H = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = list(map(lambda x: int(x)-1, input().split()))
    edges[a].append(b)
    edges[b].append(a)


ans = [0]*n


def dfs(v, parent):
    if visited[v]:
        return 0
    visited[v] = 1
    # hight = H[v]
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v)
        if H[v] <= H[v2]:
            break
    else:
        ans[v] = 1


visited = [0]*n

for v in range(n):
    if visited[v]:
        continue
    dfs(v, -1)

print(sum(ans))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

def main():
    mod=10**9+7
    N,M=MI()
    H=LI()
    adj=[[]for _ in range(N)]
    for i in range(M):
        a,b=MI()
        a-=1
        b-=1
        adj[a].append(b)
        adj[b].append(a)
        
    used=[0]*N
    Hi=[[0,0]for _ in range(N)]
    for i in range(N):
        Hi[i][0]=H[i]
        Hi[i][1]=i
        
    Hi.sort(reverse=True)
    
    ans=0
    for i in range(N):
        if used[i]==0:
            v=Hi[i][1]
            ans+=1
            used[v]=1
            for nv in adj[v]:
                used[nv]=1
                
    print(ans)
        
    

main()

Submission status: Wrong Answer

Solution code:
int1 = lambda x: int(x) - 1

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

nei = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int1, input().split())
    nei[A].append(B)
    nei[B].append(A)

good = [True] * N

for i in range(N):
    if good[i]:
        for n in nei[i]:
            if H[i] <= n:
                good[i] = False
                break
            else:
                good[n] = False

print(sum(good))

Submission status: Wrong Answer

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

    if h[a-1] < h[b-1]:
        lis[a-1] = 0
        h[a-1] = h[b-1]
    elif h[a-1] > h[b-1]:
        lis[b-1] = 0
        h[b-1] = h[a-1]
    else:
        lis[a-1]=0
        lis[b-1]=0

print(len([i for i in lis if i == 1]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N,M = map(int,input().split())
    H = tuple(map(int,input().split()))
    good = [1]*N
    for _ in range(M):
        a,b = map(int,input().split())
        a-=1;b-=1
        if H[a]<H[b]:
            good[a] = 0
        elif H[a] > H[b]:
            good[a] = 0
            good[b] = 0
        else:
            good[b] = 0
    print(good.count(1))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1

"""

import collections
import itertools
import operator


class UnionFind:
    def __init__(self, x):
        class KeyDict(dict):
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()
        self.rank = collections.defaultdict(int)
        self.size = collections.defaultdict(lambda: 1)
        if x is not None:
            for elem in range(x+1):
                _, _, _ = self.parent[elem], self.rank[elem],self.size[elem]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if not self.are_same(x,y):
            xx = self.size[x]
            yy = self.size[y]
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += xx
            else:
                self.parent[y] = x
                self.size[x] += yy
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def Size(self,x):
        return self.size[self.find(x)]

    def are_same(self, x, y):
        '''print(x,y,self.find(x),self.find(y),self.find(x) == self.find(y))'''
        return self.find(x) == self.find(y)

    def grouper(self):
        roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
        root = operator.itemgetter(1)
        for _, group in itertools.groupby(sorted(roots, key=root), root):
            yield [x for x, _ in group]

n,k = m()

h = l()

po = [1 for i in range(n)]

for i in range(k):
    a,b = m()
    if a >b:
        po[b-1] = 0
    elif a == b:
        po[a-1] = 0
    else:
        po[b-1] = 0
co = 0

for i in range(n):
    if po[i] == 1:
        co += 1



print(co)

Submission status: Wrong Answer

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

V = []
for node in range(N):
    V.append(set())
for _ in range(M):
    a,b = map(int, input().split())
    V[a-1].add(b-1)
    V[b-1].add(a-1)

ans = 0
for node in range(N):
    Hi = H[node]
    flg = 0
    for next_node in V[node]:
        if Hi>H[next_node]:
            continue
        flg = 1
    if flg==1:
        ans = ans + 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
good = [True] * (N+1)  # 1-indexed
H = [0] + lr()  # 1-indexed
for _ in range(M):
    a, b = lr()
    if H[a] >= H[b]:
        good[b] = False
    elif H[a] <= H[b]:
        good[a] = False

answer = sum(good) - 1
print(answer)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n , m = map(int , input().split())
h  = list(map(int , input().split()))
dic = defaultdict(list)
for i in range(m):
	u , v = map(int , input().split())
	dic[u].append(v)
	dic[v].append(u)
ans = 0
for i in range(1, n+1):
	currh = h[i-1]
	f = 1
	if i in dic: 
		for obs in dic[i]:
			if h[obs-1] > currh:
				f = 0
				break
		if f:
			ans+=1
	else:
		ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def mips():
    return map(int,input().split())
def msps():
    return map(str,input().split())
N,M = mips()
H = [el for el in mips()]
G = dict()
ans = 0
no = 0
for i in range(1,N+1):
    G[i] = []
for i in range(M):
    a,b = mips()
    G[a].append(b)
    G[b].append(a)
for i in range(1,N+1):
    if G[i] == []:
        ans += 1
    else:
        for el in G[i]:
            if el > i:
                no = 1
                break
    if no == 0:
        ans += 1
    no = 0
print(ans)

Submission status: Wrong Answer

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

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

#良ければ１、
result=[1]*n

for _ in range(m):
    a,b=map(int,input().split())
    a=a-1
    b=b-1

    if h[a]<h[b]:
        result[a]=0
    else:
        result[b]=0

cnt=0
for item in result:
    if item==1:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

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

flags = [True] * n

for _ in range(m):
    a, b = map(int, input().split())
    if h[a-1] > h[b-1]:
        flags[b-1] = False
    if h[b-1] > h[a-1]:
        flags[a-1] = False
    else:
        flags[a-1] = False
        flags[b-1] = False

print(flags.count(True))

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline


class UnionFind:
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1] * (n + 1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0] * (n + 1)

    # ノードxのrootノードを見つける
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.find_root(x)
        y = self.find_root(y)
        # すでに同じ木に属していた場合
        if x == y:
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    # ノードxが属する木のサイズを返す
    def get_size(self, x):
        return -self.root[self.find_root(x)]


N, M = map(int, readline().split())
H = list(map(int, readline().split()))
uf = UnionFind(N)
for _ in range(M):
    A, B = map(int, readline().split())
    A -= 1
    B -= 1
    uf.unite(A, B)

answer = sum(1 for i in uf.root if i < 0)
print(answer)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M = mi()
A = li()

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

for i in range(M):
    a, b = mi()
    a -= 1
    b -= 1
    flag[a] = max(A[a], A[b], flag[a])
    flag[b] = max(A[a], A[b], flag[a])
cnt = 0
for i in range(N):
    if A[i] == flag[i]:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

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

good = [True for i in range(n)]

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

result = 0
for x in good:
	if not x:
		result += 1

print(result)

Submission status: Wrong Answer

Solution code:
#!python3

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


def main():
    link = [[] for _ in range(N)]
    for a, b in AB:
        link[a - 1].append(b - 1)
        link[b - 1].append(a - 1)

    ans = N
    for i in range(N):
        for x in link[i]:
            if H[i] <= H[x]:
                print(i, H[i], x, H[x])
                ans -= 1
                break
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
h = list(map(int, readline().split()))
ab = [list(map(int, readline().split())) for _ in range(m)]
memo = [True] * n
check = [False] * n
cnt = 0
for a, b in ab:
    check[a - 1] = True
    check[b - 1] = True
    if h[a - 1] > h[b - 1]:
        memo[b - 1] = False
    elif h[a - 1] < h[b - 1]:
        memo[a - 1] = False
for i in range(n):
    if memo[i] and check[i]:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().split())
    H=list(map(int,readline().split()))
    A=[]
    B=[]
    for i in range(M):
        a,b=map(int,readline().split())
        A.append(a)
        B.append(b)

    flags=[True]*N
    for i in range(M):
        a=A[i]-1
        b=B[i]-1
        if H[a]<H[b]:
            flags[a]=False
        else:
            flags[b]=False

    res=0
    for i in range(N):
        if flags[i]:
            res+=1

    print(res)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

memo = [1] * (n)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a > b:
        memo[a] = 0
    else:
        memo[b] = 0
print(sum(memo))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
h = [int(item) for item in input().split()]
ans = [True] * n
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    if h[a] >= h[b]:
        ans[b] = False
    elif h[b] >= h[a]:
        ans[a] = False

print(sum(ans))

Submission status: Wrong Answer

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

graph = [[] for _ in range(N)]
for a, b in X:
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

ans = [True] * N
for u in range(N):
    for v in graph[u]:
        ans[u] &= H[u] > H[v]

print(sum(ans[1:]))

Submission status: Wrong Answer

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

e = [set() for _ in range(n)]
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    e[u].add(v)
    e[v].add(u)

res = 0
for u in range(n):
    flag = True
    h = hl[u]
    for v in e[u]:
        if hl[v]>u:
            flag = False
            break
    if flag:
        res += 1
print(res)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m = MAP()
h = LIST()
flag = [1 for _ in range(n)]
for i in range(m):
    a, b = MAP()
    if h[a - 1] >= h[b - 1]:
        flag[b - 1] = 0
    elif h[a - 1] <= h[b - 1]:
        flag[a - 1] = 0
print(sum(flag))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
H = list(map(int,input().split()))
ans = [i 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]:
        if A in ans:    
            ans.remove(A)
        if B in ans:    
            ans.remove(B)
    elif H[A - 1] < H[B - 1]:
        if A in ans:
            ans.remove(A)
    else:
        if B in ans:
            ans.remove(B)
    
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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)]
A = np.array(A)
B = np.array(B)
sum = 0
num = 1
while num <= N:
    sta = 1
    AB_tmp = []
    A_tmp =list(zip(*np.where(A == num )))
    B_tmp =list(zip(*np.where(B == num )))
    for i in range(len(A_tmp)):
        if B[A_tmp[i][0]] not in AB_tmp:
            AB_tmp.append(B[A_tmp[i][0]])
    for i in range(len(B_tmp)):
        if A[B_tmp[i][0]] not in AB_tmp:
            AB_tmp.append(A[B_tmp[i][0]])
    for i in range(len(AB_tmp)):
        num_tmp = AB_tmp[i]-1
        if (H[num - 1]<= H[num_tmp]):
            sta = 0
    if sta == 1:
        sum += 1
    num += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
high = list(map(int,input().split()))
deck = list(range(1,n+1))

for x in range(m):
    a,b = map(int,input().split())
    if high[a-1] == high[b-1]:
        if a in deck:
            deck.remove(a)
        if b in deck:
            deck.remove(b)
    elif high[a-1] > high[b-1]:
        if b in deck:
            deck.remove(b)
    else:
        if a in deck:
            deck.remove(a)

good_deck = len(deck)
print(good_deck)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
high = list(map(int,input().split()))
deck = []
for z in range(1,n+1):
    deck.append(z)

kumiawase = []

for x in range(m):
    kumi = list(map(int,input().split()))
    kumiawase.append(kumi)

for y in kumiawase:
    if high[y[0]-1]==high[y[1]-1]:
        if y[0] in deck:
            deck.remove(y[0])
        if y[1] in deck:
            deck.remove(y[1])
    elif high[y[0]-1] > high[y[1]-1]:
        if y[1] in deck:
            deck.remove(y[1])
    else:
        if y[0] in deck:
            deck.remove(y[0])

good_deck = len(deck)

print(good_deck)

Submission status: Time Limit Exceeded

Solution code:
ri = lambda: map(int, input().split())

N, M = ri()
H = list(ri())
G = [[0]*N for _ in range(N)]
for _ in range(M):
    a, b = ri()
    G[a-1][b-1] = H[b-1]
    G[b-1][a-1] = H[a-1]

T = [max(r) for r in G]
print(sum(1 for i, h in enumerate(T) if h == 0 or h < H[i]))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A, B = [], []
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(N):
    L = []
    if i+1 not in A and i+1 not in B:
        ans += 1
    else:
        for j in range(M):
            if A[j] == i+1:
                if H[A[j]-1] != H[B[j]-1]:
                    L.append(H[A[j]-1])
                    L.append(H[B[j]-1])
            elif B[j] == i+1:
                if H[A[j]-1] != H[B[j]-1]:
                    L.append(H[A[j]-1])
                    L.append(H[B[j]-1])
        if len(L) == 0:
            d = 1
        elif max(L) == H[i]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1, N+1):
  # ノードi(=1,...,N)と結合しているノードを全て求め、connectに格納
  connect = []
  for j in range(M):
    if i in l[j]:
      if i == l[j][0]: connect.append(l[j][1])
      else: connect.append(l[j][0])
  
  # ノードiの標高が、結合している任意のノードの標高より高いなら ans += 1
  n = 0
  for c in connect:
    if H[i-1] > H[c-1]: n += 1
  if n == len(connect): ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
r = [list(map(int, input().split())) for i in range(m)]
N = list(range(n))
for i in range(m):
    x = r[i][0] - 1
    y = r[i][1] - 1
    if h[x] > h[y]:
        if y in N:
            N.remove(y)
    elif h[x] < h[y]:
        if x in N:
            N.remove(x)
    else:
        if x in N:
            N.remove(x)
        if y in N:
            N.remove(y)
print(len(N))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = []
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(N):
    flag = 0
    for j in range(M):
        if A[j] == i+1:
            if H[B[j]-1] >= H[i]:
                flag = 1
        if B[j] == i+1:
            if H[A[j]-1] >= H[i]:
                flag = 1
    if flag == 0:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = [int(x) for x in input().split()]
H = [float(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(M)]

graph = [[0 for _ in range(N)] for _ in range(N)]

for A, B in AB:
  graph[A-1][B-1] = 1
  graph[B-1][A-1] = 1

ans = 0
for i in range(N):
  h = 0
  for j in range(N):
    if(graph[i][j]!=0):
      if(H[i]<=H[j]):
        h += 1
        break
  if(h==0):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
AB_ls, cnt = [], 0
for i in range(M):
    AB_ls.append(list(map(int, input().split(' '))))
for i in range(N):
    val = H_ls[i]
    is_peak = True
    for s in AB_ls:
        if not is_peak:
            break
        ls = []
        if (i + 1) in s:
            [ ls.append(x) for x in s if x != (i + 1)]
            if val <= H_ls[ls[0] - 1]:
                is_peak = False
                break
    if is_peak:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
AB_ls, cnt = [], 0
for i in range(M):
    AB_ls.append(list(map(int, input().split(' '))))
for i in range(N):
    val = H_ls[i]
    is_peak = True
    for s in AB_ls:
        ls = []
        if (i + 1) in s:
            [ ls.append(x) for x in s if x != (i + 1)]
            if val <= H_ls[ls[0] - 1]:
                is_peak = False
                break
    if is_peak:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
s = {}
lst = list(map(int, input().split()))

anslst = []

for i in range(N):
    s[i+1] = lst[i]

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

    if s[A] <= s[B] and A not in anslst:
        anslst.append(A)
    if s[B] <= s[A] and B not in anslst:
        anslst.append(B)

print(N - len(anslst))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n):
    flag = True
    for j in range(n):
        if ab[i][j] == 1:
            if h[j] >= h[i]:
                flag = False
                break
    if flag:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

badcnt = 0
for i in range(n):
  for j in range(m):
    if (i+1 == a[j]) or (i+1 == b[j]):
      if min(h[a[j]-1], h[b[j]-1]) == h[i]:
        badcnt += 1
        break
ans = n - badcnt        
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1,n+1):
    max_hight = 0
    j = 0
    while i in a[j:]:
        index = j + a[j:].index(i)
        hight = h[b[index]]
        max_hight = max(max_hight, hight)
        j = index + 1
    j = 0
    while i in b[j:]:
        index = j + b[j:].index(i)
        hight = h[a[index]]
        max_hight = max(max_hight, hight)
        j = index + 1
    if h[i] > max_hight:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H = [int(i) for i in input().split()]
AB = [list(map(int,input().split())) for _ in range(M)]
list_N = list(range(1,N+1))
for j in range(M):
    if H[AB[j][0]-1]<H[AB[j][1]-1]:
        if AB[j][0] in list_N:
            list_N.remove(AB[j][0])
    elif H[AB[j][0]-1]>H[AB[j][1]-1]:
        if AB[j][1] in list_N:
            list_N.remove(AB[j][1])
    else:
        if AB[j][0] in list_N:
            list_N.remove(AB[j][0])
        if AB[j][1] in list_N:
            list_N.remove(AB[j][1])
print(len(list_N))

Submission status: Time Limit Exceeded

Solution code:
N,M = (int(x) for x in input().split())
H = list(map(int, input().split()))
n_list = [int(i+1) for i in range(N)]
n_remove = []

for j in range(M):
  A,B = (int(x) for x in input().split())
  if H[A-1]>H[B-1]:
    if B in n_list:
      n_remove.append(B)
  elif H[A-1]<H[B-1]:
    if A in n_list:
      n_remove.append(A)
  else:
    if set([A,B]) & set(n_list) != set():
      E = list(set([A,B]) & set(n_list))
      n_remove+=E

print(len(list(set(n_list) - set(n_remove))))