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(e) for e in input().split()]
h = [int(e) for e in input().split()]
a=[0]*m
b=[0]*m
for i in range(m):
    a[i],b[i] = [int(e) for e in input().split()]
res = 0
no = set()
for i in range(m):
    if h[a[i]-1] < h[b[i]-1]:
        no.add(a[i])
    elif h[a[i]-1] < h[b[i]-1]:
        no.add(b[i])
    else:
        no.add(b[i])
        no.add(a[i])
print(n-len(no))

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
h = list(map(int, input().strip().split()))

g = [[0] * (n+1) for i in range(n+1)]
for i in range(1,n+1):
    g[i][i] = h[i-1]


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

#for i in range(1,n+1):
#    print(g[i,:])


ans = 0
for i in range(1,n+1):
    if np.argmax(g[i]) == i:
        #print(i)
        ans += 1

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 0
for i in range(n):
    if len(table[i]) > 0:
        if h[i] >= max(table[i]):
            ans += 1
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, m = LI()
    h = LI()
    ab = LIR_(m)
    ans = [1] * n
    for a, b in ab:
        if h[a] < h[b]:
            ans[a] = 0
        else:
            ans[b] = 0
    print(sum(ans))
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
graph={}
for i in range(m):
    a,b=map(int,input().split())
    if(graph.get(a,None)==None):
        if(h[a-1]>h[b-1]):
            graph[a]=1
        else:
            graph[a]=0
    else:
        if(h[a-1]<h[b-1]):
            graph[a]=0
    if(graph.get(b,None)==None):
        if(h[b-1]>h[a-1]):
            graph[b]=1
        else:
            graph[b]=0
    else:
        if(h[b-1]<h[a-1]):
            graph[b]=0
ans=0
temp=[1]*n
for i in graph:
    if(graph[i]):
        ans+=1
    temp[i-1]=0
ans+=sum(temp)
print(ans)

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
graph = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    graph[a - 1].add(b - 1)
    graph[b - 1].add(a - 1)

good = [-1] * N
for i in range(N):
    if good[i] != -1:
        continue
    if not graph[i]:
        print(i)
        good[i] = 1
    elif all(H[nei] < H[i] for nei in graph[i]):
        good[i] = 1
        for nei in graph[i]:
            good[nei] = 0
    else:
        good[i] = 0

print(sum(good))

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m = [int(i) for i in input().split()]

h = [int(i) for i in input().split()]

l = [[int(i)-1 for i in input().split()] for _ in range(m)]

ans = np.array([1 for _ in range(n)])

for x,y in l:
    if h[x]>=h[y]:
        ans[y] = 0
    else:
        ans[x] = 0
        
print(np.count_nonzero(ans))

Submission status: Wrong Answer

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

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

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

for a,b in AB:
    try:
        if H[a-1] < H[b-1]:
            good_tembodai.remove(a)
        else:
            good_tembodai.remove(b)
    except ValueError:
        continue
print(len(good_tembodai))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))


n,m = MI()
h = LI()
a = []
b = []
d = defaultdict(str)
for _ in range(m):
	aa,bb = MI()
	d[str(aa-1)] = ':'+str(h[bb-1])
	d[str(bb-1)] += ':'+str(h[aa-1])
ans=0
for i in range(n):
	tmp = d[str(h[i])]
	k = 1
	if len(tmp)>0:
		tmp = [int(s) for s in tmp.split(':') if not s=='']
		for s in tmp:
			if int(h[i])<=s:
				k = 0
	ans+=k
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
j = set()
#ab = [list(map(int,input().split()))for i in range(m)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] >= h[b-1]:
        j.add(b)
    elif h[b-1] >= h[a-1]:
        j.add(a)
print(n-len(j))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
a, b = [0] * m, [0] * m
data = [[] for _ in range(n)]
for i in range(m):
    a[i], b[i] = map(int, input().split())
    data[a[i] - 1].append(b[i] - 1)
    data[b[i] - 1].append(a[i] - 1)
ans = 0
for i in range(n):
    flag = True
    if len(data[i]) == 0:
        continue 
    for x in data[i]:
        if h[i] < h[x]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

print(len(set(h) - set(to_remove)))

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
H=list(map(int, input().split()))
tenbo=[True]*N
for i in range(M):
    A,B=map(int, input().split())
    if H[A-1]>=H[B-1]:#Aが大きい
        tenbo[B-1]=False
    elif H[A-1]<=H[B-1]:
        tenbo[A-1]=False
print(sum(tenbo))

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
#a = []
#b = []

result = [True] * n

for i in range(m):
    aa, bb = list(map(int, input().split()))
    if h[aa-1] >= h[bb-1]:
        result[bb-1] = False
    else:
        result[aa-1] = False

#print(result)
s = 0
for i in range(n):
    if result[i]:
        s += 1
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

print(sum(ls))

Submission status: Wrong Answer

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

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

# 展望台から行ける展望台の高さを格納しておく
from collections import defaultdict
d = defaultdict(int)
for i in range(M):
  A,B = list(map(int,input().split()))
  A -= 1
  B -= 1
  if d[A] < H[B]:
    d[A] = H[B]
  if d[B] < H[A]:
    d[B] = H[A]
cnt = 0
for idx,h in enumerate(H):
  if d[idx] == 0 or h < d[idx]:
    cnt += 1
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
H = list(map(int,input().split()))
ans = [0 for i in range(N)]
R = []
for i in range(M):
    R.append(list(map(int,input().split())))
R.sort()
for a,b in R:
    if H[a-1] < H[b-1]:
        ans[a-1] += 1
    else:
        ans[b-1] += 1
print(ans.count(0))

Submission status: Wrong Answer

Solution code:
def resolve():
	n, m = map(int, input().split())
	bs = [[i] for i in list(map(int, input().split()))]
	for i in range(m):
		a, b = map(int, input().split())
		bs[a-1].append(b-1)
		bs[b-1].append(a-1)
	ans = 0
	for v in bs:
		if len(v) != 1 and v[0] > max(v[1:]):
			ans += 1
	print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N ,M = map(int,input().split())
H = list(map(int,input().split()))
graph = defaultdict(set)
for _ in range(M-1):
    A, B = map(int,input().split())
    graph[A].add(B)
    graph[B].add(A)

cnt = 0
for i in range(1,N+1):
    t = H[i-1]
    flg = 0
    for j in graph[i]:
        if H[j-1] >= t:
            flg = 1
            break
    if flg == 0:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict
N,M = [int(x) for x in stdin.readline().rstrip().split()]
H = [int(x) for x in stdin.readline().rstrip().split()]
d = defaultdict(set)
for i in range(M):
    A,B = [int(x) for x in stdin.readline().rstrip().split()]
    d[A].add(B)
    d[B].add(A)
    
ans = 0
for h in range(1,N+1):
    f = True
    for i in d[h]:
        if H[i-1] > h:
            f = False
    if f:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n, m = sp()
h = l()
graph = dd(set)
for i in range(m):
    u, v = sp()
    graph[u].add(v)
    graph[v].add(u)
answer = 0
for i in graph.keys():
    result = True
    for j in graph[i]:
        if h[j-1] > h[i-1]:
            result = False
            break
    if result:
        answer += 1
out(answer)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
peaks = list(map(int, input().split()))
ng_peaks = set([])
for j in range(M):
    A_j, B_j = map(int, input().split())
    if peaks[A_j-1] >= peaks[B_j-1]:
        ng_peaks.add(B_j)
    elif peaks[A_j-1] < peaks[B_j-1]:
        ng_peaks.add(A_j)
print(N-len(ng_peaks))

Submission status: Wrong Answer

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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



class Graph(object):
    def __init__(self, n:int):
        """ ノードのつながりを辞書型で表現する
        要素数nであり、要素は0からn-1である想定
        >> - usage
        g = Graph(n=n)

        """
        self.adjacency_dict = {}
        self.val = [0] * n
        self.good = [1] * n
        self.n = n
        for i in range(n):
            self.add_vertex(i)

    def add_vertex(self, v: int):
        """ ノードを追加する """
        self.adjacency_dict[v] = []

    def add_edge(self, v1: int, v2: int, undirected=False):
        self.adjacency_dict[v1].append(v2)
        if undirected:
            self.adjacency_dict[v2].append(v1)


g = Graph(N)

h = list(map(int, input().split()))
for i in range(N):
    g.val[i] = h[i]

for m in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g.add_edge(a, b, undirected=True)
    val_a, val_b = h[a], h[b]

    if val_a == val_b:
        g.good[a] = 0
        g.good[b] = 0
    if val_a > val_b:
        g.good[b] = 0
    if val_a < val_b:
        g.good[a] = 0


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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
Y = [1]*N
for i in range(M):
    a,b = map(int,input().split())
    if H[a-1] <= H[b-1]:
        Y[a-1] *= 0
    if H[a-1] >= H[b-1]:
        Y[b-1] *= 0
print(Y.count(0))

Submission status: Wrong Answer

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

for a, b in links:
  if H[a-1] < H[b-1]:
    survivors[a-1] = False
  else:
    survivors[b-1] = False

print(sum(survivors))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(" "))
h = list(map(int,input().split(" ")))
high = []
low = []
better = 0
for i in range(m):
  a,b = map(int,input().split(" "))
  if h[a-1] > h[b-1]:
    high.append(a)
  else:
    low.append(a)
print(n-len(set(low)))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from heapq import heappush
N, M = map(int, input().split())
H = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    heappush(graph[a], H[b])
    heappush(graph[b], H[a])
ans = 0
for i in range(N):
    if graph[i]:
        if H[i] > graph[i][-1]:
            ans += 1
    else:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [[int(i) for i in input().split()] for i in range(m)]
l = [1] * n
for i in range(m):
    if h[ab[i][0] - 1] < h[ab[i][1] - 1]:
        l[ab[i][0] - 1] = 0
    elif h[ab[i][0] - 1] < h[ab[i][1] - 1]:
        l[ab[i][1] - 1] = 0
    else:
        l[ab[i][0] - 1] = 0
        l[ab[i][1] - 1] = 0
ans = sum(l)
print(ans)

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 A >= B:
        c[B - 1] += 1
    if B >= A:
        c[A - 1] += 1
print(c.count(0))

Submission status: Wrong Answer

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

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

    else:
      ans[b-1] = 1

print(sum(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N,K=map(int,input().split())
L=list(map(int,input().split()))
Hash=defaultdict(lambda:list())
for i in range(K):
    x,y=map(int,input().split())
    Hash[x].append(y)
    Hash[y].append(x)
count=0
for i in L:
    if len(Hash[i])==0:
        count+=1
    else:
        FLAG=0
        for j in Hash[i]:
            if j>=i:
                FLAG=1
                break
        if FLAG==0:
            count+=1
print(count)

Submission status: Wrong Answer

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

ary = [0 for i in range(n)]
chk = [False for i in range(n)]
for i in range(m):
	a, b = map(int, input().split())
	chk[a-1] = True
	chk[b-1] = True
	if h[a-1] < h[b-1]:
		ary[a-1] += 1
	elif h[a-1] > h[b-1]:
		ary[b-1] += 1
	else:
		continue

cnt = 0
for i in range(n):
	if ary[i] == 0 and chk[i] == True:
		cnt += 1
print (cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
s = set(range(1, n+1))
a, b = [], []

for i in range(m):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)

    if h[A-1] < h[B-1]:
        if A in s:
            s.remove(A)
    else:
        if B in s:
            s.remove(B)

# print(a, b)
# print(s)

print(len(s))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
def dfs(v, graph, seen):
    seen[v] = True
    for node in graph[v]:
        if seen[node] == True:
            continue
        dfs(node, graph, seen)

def main():
    N, M = map(int, input().split())
    graph = {}
    seen = [False for _ in range(N)]
    H = list(map(int, input().split()))
    for i in range(N):
        graph[i] = set()

    for Mi in range(M):
        a, b = map(int, input().split())
        graph[a-1].add(b-1)
        graph[b-1].add(a-1)

    count = 0
    for v in range(N):
        if seen[v] == True:
            continue
        dfs(v, graph, seen)
        count += 1
    print(count+1)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq

def bfs(c,nu,di,node,val):
    c[nu]=True
    di[val[nu]]+=1
    for each in node[nu]:
        if c[each]:
            continue
        di=bfs(c,each,di,node,val)
    return di





n,k=list(map(int,input().split()))
h=list(map(int,input().split()))
node=[i for i in h]
for _ in range(k):
    i,v=list(map(int,input().split()))
    i-=1
    v-=1
    """
    if node[i]>node[v]:
        node[v]=node[i]
    elif node[i]<node[v]:
        node[i]=node[v]
    """
    node[i]=max(node[i],h[v])
    node[v]=max(node[v],h[i])


check=[False for _ in range(n)]
ans=0
for i in range(n):
    if node[i]==h[i]:
        ans+=1
print(ans)

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 = [1]*N
for i in range(N):
    flag[i] = A[i]
flag2 = [0]*N

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])
    if A[a] == A[b]:
        flag2[a] = flag2[b] = 1
    
cnt = 0
for i in range(N):
    if A[i] >= flag[i] and not flag2[i]:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
hs = [0]
ans = [0]
aaaa = list(map(int, input().split()))
ans.extend([1]*n)
hs.extend(aaaa)

for i in range(m):
    a, b = map(int, input().split())
    if hs[a] < hs[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()))
bridge = []
connected = [0 for _ in range(n)]
good = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if h[a] < h[b]:
        good[b] += 1
    elif h[b] < h[a]:
        good[a] += 1
    connected[a] = 1
    connected[b] = 1

noc = connected.count(0)
gc = n - good.count(0)

print(noc + gc)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

G = {}

for i in range(1, N+1):
    G[i] = []
for i in range(M):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

ans = 0
for n, miti in G.items():
    f = True
    if len(miti)==0: f = False
    miti = list(set(miti))
    for m in miti:
        if H[n-1] < H[m-1]:
            f = False
            break
    if f: ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n, m = map(int, input().split())
elivation = list(map(int, input().split()))

observation_joint = defaultdict(list)

while m:
    a,b = map(int, input().split())
    a-=1
    b-=1
    observation_joint[a].append(b)
    observation_joint[b].append(a)
    m-=1

count = 0
for obs, joints in observation_joint.items():
    if joints == []:
        count += 1
    else:
        good_obs = True
        for obs2 in joints:
            if elivation[obs2] > elivation[obs]:
                good_obs = False
                break
        if good_obs:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N,M=list(map(int,input().split()))
h_list=list(map(int,input().split()))
h2_list=[True]*N

for _ in range(M):
    A,B=list(map(int,input().split()))
    if h_list[A-1] < h_list[B-1]:
        h2_list[A-1] = False
    elif h_list[A-1] > h_list[B-1]:
        h2_list[B-1] = False
    else:
        h2_list[A-1] = False
        h2_list[B-1] = False


ans = 0
for h2 in h2_list:
    if not h2:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
ab_list = [list(map(int, input().split())) for _ in range(m)]

ans_set = set()
for ab in ab_list:
    a = ab[0]
    b = ab[1]
    win = a if h_list[a-1] > h_list[b-1] else b
    ans_set.add(win)
print(len(ans_set))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
G = [[0]*N for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A-1][B-1] = 1
    G[B-1][A-1] = 1

cnt = 0
for i in range(N):
    flag = False
    for j in range(N):
        if G[i][j] == 1:
            if H[i] < H[j]:
                break
            else:
                flag = True
    if flag:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

flag=np.zeros(n)+1

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

ans=np.sum(flag)
print(int(ans))

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int,input().split())
    H = list(map(int, input().split()))
    ans = [1] * n
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        if H[a] < H[b]:
            ans[b] = 1 & ans[b]
            ans[a] = 0 & ans[a]
        else:
            ans[b] = 0 & ans[b]
            ans[a] = 1 & ans[a]
    cnt = ans.count(1)
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h_array = [int(x) for x in input().split()]
higest = [-1 for x in range(n)]
res = 0
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    higest[a] = max(higest[a], max(h_array[a], h_array[b]))
    higest[b] = max(higest[b], max(h_array[a], h_array[b]))

for i, j in zip(h_array, higest):
    if i == j:
        res += 1
print(res)

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, m = MAP()
H = LIST()
low = set([])
for i in range(m):
    a, b= MAP()
    if H[a-1] < H[b-1]:
        low = set(list(low) + [a-1, ])
    else:
        low = set(list(low) + [b-1, ])

print(n-len(low))

Submission status: Wrong Answer

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

flag=np.zeros(n)+1

for i in range(m):
  a,b=list(map(int,input().split()))
  if h[a-1]>h[b-1]:
    flag[b-1] = 0
  else:
    flag[a-1] = 0
    
print(flag)
ans=np.sum(flag)
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N,K=map(int,input().split())
L=list(map(int,input().split()))
Hash=defaultdict(lambda:list())
for i in range(K):
    x,y=map(int,input().split())
    Hash[x].append(y)
    Hash[y].append(x)
count=0
for i in L:
    if len(Hash[i])==0:
        count+=1
    else:
        FLAG=0
        for j in Hash[i]:
            if j>i:
                FLAG=1
                break
        if FLAG==0:
            count+=1
print(count)

Submission status: Wrong Answer

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

good_obs = [True] * n
for a, b in edges:
    if h[a - 1] >= h[b - 1]:
        good_obs[b - 1] = False
    elif h[b - 1] >= h[a - 1]:
        good_obs[a - 1] = False

print(sum(good_obs))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
i=h.index(max(h))+1
num=0
for _ in range(m):
    if i in list(map(int, input().split())):
        num += 1
print(num+1)