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 = list(map(int, input().split()))
ab_list = [list(map(int, input().split())) for _ in range(m)]

stock_dict = {}
used_set = set()
for ab in ab_list:
    a = ab[0] - 1
    b = ab[1] - 1
    used_set.add(a)
    used_set.add(b)

    if not(a in stock_dict):
        stock_dict[a] = []
    if not(b in stock_dict):
        stock_dict[b] = []

    stock_dict[a].append(b)
    stock_dict[b].append(a)
# print(stock_dict)

ans_set = set()
for k, v in stock_dict.items():
    for i in v:
        if h_list[k] > h_list[i]:
            ans_set.add(k)
        else:
            if k in ans_set:
                ans_set.remove(k)

for i in range(len(h_list)):
    if not(i in used_set):
        ans_set.add(i)
# print(ans_set)
print(len(ans_set))

Submission status: Wrong Answer

Solution code:
NM =input().split()
N = int(NM[0])
M = int(NM[1])
H = input().split()
Nout = [1] * N
for i in range(M):
	road = input().split()
	if float(H[int(road[0]) - 1]) < float(H[int(road[1]) - 1]):
		Nout[int(road[0]) - 1] = 0
	else:
		Nout[int(road[1]) - 1] = 0
def calc():
	j = 0
	for i in Nout:
		j += i
	return j
print(calc())

Submission status: Wrong Answer

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

H = input().split()
H2 = [0] * N
for i in range(K):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        H2[b-1] = 1
    elif H[a-1] < H[b-1]:
        H2[a-1] = 1
    elif H[a-1] == H[b-1]:
        H2[b-1] = 1
        H2[a-1] = 1

count = 0
for i in H2:
    if i == 0:
        count+=1
print(count, end = "")

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
A = []
B = []
ans = 0
H = list(map(int,input().split()))
for i in range(m-1):
    a, b = map(int, input().split())
    A.append(int(a))
    B.append(int(b))
for i in range(m-1):
  if H[(A[i])-1] < H[(B[i])-1]:
    ans += 1
for i in range(1,m-1):
  if A.count(i) == 0 and B.count(i) == 0:
    ans += 1
for i in range(m-1):
  for j in range(m-1):
    if A[i] == B[j] and B[i] == A[j]:
      ans -= 1
print(ans)

Submission status: Wrong Answer

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

for i in range(m):
    tmpa,tmpb = map(int,input().split())
    a.append(tmpa)
    b.append(tmpb)
    ab.append((tmpa,tmpb))

ab = list(set(ab))

cnt = 0
kakunin = []
hoge = set()
for v in ab:
    # print(h[v[0]-1],h[v[1]-1])
    if h[v[0]-1] - h[v[1]-1] < 0 and (v[0] not in hoge):
        if v[0] not in kakunin:
            cnt += 1
        # kakunin.append(v[0])
        hoge.add(v[0])
        # print(kakunin)
    elif h[v[0]-1] - h[v[1]-1] == 0:
        cnt += 1
        hoge.add(v[0])

print(n - cnt)

Submission status: Wrong Answer

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

flags = ["f" for i in range(n)]

good = [0 for i in range(n)]
for i in range(m):
    line = [int(s) - 1 for s in input().split()]
    
    a = line[0]
    b = line[1]
    
    flags[a] = "t"
    flags[b] = "t"

    if high[a] > high[b]:
        if good[a] == 0:
            good[a] = 1
        if good[b] == 1:
            good[b] = 0
    
    elif high[b] > high[a]:
        if good[b] == 0:
            good[b] = 1
        if good[a] == 1:
            good[a] = 0
    
    else:
        if good[a] == 1:
            good[a] = 0
        if good[b] == 1:
            good[b] = 0

print(good.count(1) + flags.count("f"))

Submission status: Wrong Answer

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

cnt = 0
memo_loser = []
for bridge in AB:
    if H[bridge[0] - 1] == H[bridge[1] - 1]:
        if not bridge[0] in memo_loser:
            memo_loser.append(bridge[0])
        if not bridge[1] in memo_loser:
            memo_loser.append(bridge[1])
        break

    value = min(H[bridge[0]-1], H[bridge[1]-1])
    if value == H[bridge[0]-1] and not bridge[0] in memo_loser:
        memo_loser.append(bridge[0])
    elif value == H[bridge[1] - 1] and not bridge[1] in memo_loser:
        memo_loser.append(bridge[1])
print(N - len(memo_loser))

Submission status: Wrong Answer

Solution code:
l = list(map(int, input().split()))
li =  list(map(int, input().split()))
list_ = [[0 for _ in range(l[0])] for _ in range(l[0])]

for i in range(l[1]):
    e = list(map(int, input().split()))
    list_[e[0] - 1][e[1] - 1] = 1
    list_[e[1]-1][e[0] -1] = 1
    
r = 0
for n, i in enumerate(list_):
    edge = [i for i, x in enumerate(list_[1]) if x == 1]
    
    f = 0
    for j in edge:
        if li[n-1] <= j-1:
            f = 1
            break
    if f == 0:
        r += 1
        
print(r)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = list(map(int, input().split()))
Hs = list(map(int, input().split()))
A = []
B = []
for i in range(M):
  a, b = list(map(int, input().split()))
  A.append(a)
  B.append(b)
  
Hs = sorted(Hs, reverse=True)
Hs = np.array(Hs)

C = np.array(sum([A, B], []))

# 一人勝ちの奴ら
Hs_unique = Hs
Hs_unique = np.setdiff1d(Hs, C)

# 一人勝ちできなかった奴ら
for s in Hs_unique:
  Hs = Hs[Hs != s]
  
# 一人勝ちはできなかったけど勝った奴ら
win = []
A = np.array(A)
B = np.array(B)
for H in Hs:
  if H in A and sum(B > H) > 1:
    continue
  elif H in B and sum(A > H) > 1:
    continue
  else:
    win.append(H)

ans = []
ans.append(win)
ans.append(Hs_unique.tolist())
ans = sum(ans, [])
ans = np.array(ans)
print(len(ans))

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest

not_max = {}
max = {}
cnt = 0
arrived_list = []
roots = []
h =[]

def dfs(now_tenboudai):
    global arrived_list
    global cnt
    global h
    global not_max
    global max
    for root in roots:

        if root in arrived_list:
            continue

        if root[0]-1 is now_tenboudai or root[1]-1 is now_tenboudai:
            arrived_list.append(root)

            if root[0]-1 is now_tenboudai:
                target = root[1]-1
            else:
                target = root[0]-1

            # 自分より高いなら再帰的調査
            if h[now_tenboudai] < h[target]:
                not_max[now_tenboudai] = 1
                dfs(target)

            # 自分より低いならフラグだけ立てる
            else:
                not_max[target] = 1

    if now_tenboudai not in not_max.keys():
        max[now_tenboudai] = 1
    return


def resolve():
    global roots
    global cnt
    global h
    global max

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

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

    roots = [list(map(int , input().split())) for i in range(m)]

    # ここできれいにソート。
    for i in roots:
        i.sort()
    roots.sort(key=lambda xx: [xx[1], xx[0]])

    cnt = 0
    # i = 展望台の添え字
    for i in range(n):
        dfs(i)


    print(len(max))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4 3
1 2 3 4
3 1
2 3
2 4"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6"""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

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

A, B = [], []
for i in range(M):
    _a, _b = [int(x) for x in input().split()]
    A.append(_a)
    B.append(_b)

H_dic = {}
for (index, value) in enumerate(H):
    H_dic[index] = value

H_dic = sorted(H_dic.items(), key=lambda x: x[1])

H_index_2_H_dic_index = {}
index = 0
for i in H_dic:
    H_index_2_H_dic_index[index] = i[0]
    index += 1

boolTable = [[False for i in range(N)] for j in range(N)]

for i in range(M):
    a = H_index_2_H_dic_index[A[i]-1]
    b = H_index_2_H_dic_index[B[i]-1]
    boolTable[a][b] = True
    boolTable[b][a] = True

print(boolTable)

res = 0
for i in range(1, N):
    b_list = boolTable[i]
    if any(b_list[:i]):
        print(i)
        res += 1

print(res)

Submission status: Wrong Answer

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

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

ans = 0
for i in range(N): #i番目の展望台に注目
  if michi[i] == []:
    ans +=1
  else:
    for j in michi[i]:
      print(i,j,H[i],H[j])
      if H[i] < H[j]:
            break
      if j == michi[i][-1]:
          ans += 1

print(ans)

Submission status: Wrong Answer

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

print(height_list)
print(road_list)

Submission status: Wrong Answer

Solution code:
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
n,k=io()
l=op()
l.insert(0,0)
c=0
s=set()
s1=set()
fg=[0]*(n+1)
for _ in range(k):
    a,b=io()
    s1.update((a,b))
    if l[a]>l[b]:
        fg[b]=1
        s.add(a)
    elif l[a]<l[b]:
        fg[a]=1
        s.add(b)
c+=n-len(s1)
c1=0
for i in range(1,n+1):
    if fg[i]==1 and (i in s):
        # s.remove(i)
        c1+=1
print(len(s)-c1+c)

Submission status: Wrong Answer

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

ab=[]



for i in range(m):
    a1,b1=map(int,input().split())
    ab.append([a1-1,b1-1])
ab = list(map(list, set(map(tuple, ab))))

aaa=[]
for i in range(len(ab)):
    #a1,b1=map(int,input().split())
    if(h[ab[i][0]]<h[ab[i][1]]):
        aaa.append(ab[i][1])
    else:
        aaa.append(ab[i][0])


print(n-len(set(aaa)))

Submission status: Wrong Answer

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

a = [list(map(int,input().split())) for i in range(m)]

count = []

for i in range(n):
    count.append(0)

ans = []

for i in range(m):
    for j in range(2):
        count[a[i][j]-1] += 1

for i in range(m):
    if h[a[i][0]-1] < h[a[i][1]-1]:
        ans.append(h[a[i][1]-1])
    else:
        ans.append(h[a[i][0]-1])
    
ans = set(ans)

print(len(ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
H = [int(str) for str in input().strip().split()]
AB = [[int(str) - 1 for str in input().strip().split()] for _ in range(M)]


def solve():
    G = [[False] * N for _ in range(N)]
    for a, b in AB:
        G[a][b] = True
        G[b][a] = True

    idxs = list(range(N))
    idxs.sort(key=lambda x: H[x], reverse=True)

    ans = 0
    for i in range(N):
        best = True
        for j in idxs[:i]:
            if G[idxs[i]][j]:
                best = False
                break
        if best:
            ans += 1

    print(ans)


solve()

Submission status: Wrong Answer

Solution code:

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

ans_list=list(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_list:
            ans_list.remove(a)
    if H[a-1]>H[b-1]:
        if b in ans_list:
            ans_list.remove(b)
print(len(ans_list))

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:
    cnt=0
    if r==0:
        continue
    for i in r:

        if H[idx] <= H[i-1]:
            continue

        if cnt==(len(r)-1):
            count.append(idx)
        cnt+=1

    idx+=1

print(len(set(count)))

Submission status: Wrong Answer

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(hasi)

goodHasiCount = 0
for i in range(tenbodaiCount):
    targetHasiList = []
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 2, hasi))) > 0:
            targetHasiList.append(hasi)
    isGoodHasi = True
    for j in range(len(targetHasiList)):
        a = targetHasiList[j][0]
        b = targetHasiList[j][1]
        if a == i:
            if b > a:
                isGoodHasi = False
        else:
            if a > b:
                isGoodHasi = False

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
count = 0
vcount = [0]*n
#arr = []
d = {}
for i in range(m):
    a,b = map(int,input().split())
    jk = [a,b]
    jk.sort()
    vcount[a-1] = 1
    vcount[b-1] = 1
    # arr.append([a,b])
    k1 = jk[0]
    k2 = jk[1]
    d.setdefault(k1, [])
    d.setdefault(k2, [])
    flag = 0
    if((jk[0] in d.get(jk[1]))):
        flag = 1
    if(flag==0):

        d[k1].append(k2)
        d[k2].append(k1)
        #arr.append(jk)
    else:
        #arr.remove(jk)
        d[jk[0]].remove(jk[1])
        d[jk[1]].remove(jk[0])
         
#print(d)
for key in d:
    flag = 0
    gg = d.get(key)
    if(gg):
        for i in gg:
            if(h[key-1]<=h[i-1]):
                flag = 1
                break
        if(flag==0):
            #print(key)
            count+=1
#print(count,sum(vcount))
print(count+n-sum(vcount))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
h = list(map(int, input().split()))
ab= list(list(map(int,input().split())) for _ in range(m))
ans = 0
h2 = {}
for i in range(n):
    h2[i+1] = h[i]
w = []
for i in range(m):
    c = [h2[ab[i][0]], h2[ab[i][1]]]
    w.append(c)

for i in h:
    w2 = []
    for j in w:
        if i in j:
            w2.append(j)
    else:
        w2 = set(sum(w2,[]))
        try:
            if max(w2) == i:
                ans += 1
        except:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
flags = list([0]*N)
import numpy as np
AB = list()
for i in range(M):
    A, B = map(int, input().split())
    AB.append([A,B])
AB = list(map(list, set(map(tuple, AB))))
for A, B in AB:
    if(flags[B-1] != 0 and flags[A-1] != 0):
        if(H[flags[A-1]-1] > H[flags[B-1]-1]):
            flags[B-1] = flags[A-1]
        else:
            flags[A-1] = flags[B-1]
    elif(flags[B-1] != 0 and flags[A-1] == 0):
        if(H[A-1] > H[flags[B-1]-1]):
            flags[B-1] = A
        else:
            flags[A-1] = flags[B-1]
    elif(flags[B-1] == 0 and flags[A-1] != 0):
        if(H[flags[A-1]-1] > H[B-1]):
            flags[B-1] = flags[A-1]
        else:
            flags[A-1] = B
    else:
        if(H[A-1] > H[B-1]):
            flags[B-1] = A
        else:
            flags[A-1] = B
    #print(flags)
print(np.sum(np.array(flags)==0))

Submission status: Wrong Answer

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

    pool = []
    for i in range(m):
        a,b = array[i]
        if H[a-1] <= H[b-1]:
            pool.append(a)
        else:
            pool.append(b)
    ans = len(set(range(1, n+1)) - set(pool))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(m):
    road[i] = list(map(int, input().split()))

for j in range(m):
    if H[road[j][0]-1] < H[road[j][1]-1]:
        ans[road[j][0]-1] = 1
    elif H[road[j][0]-1] == H[road[j][1]-1]:
        ans[road[j][0]-1] = 1
        ans[road[j][1]-1] = 1

total = sum(ans)
print(n-total)

Submission status: Wrong Answer

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

ansdic = {}

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n,m=list(map(int,input().split()))
h=list(map(int,input().split()))
sum=0 
dp=[float("INF") for i in range(n)]
for i in range(m):
    a,b=list(map(int,input().split()))
    if h[a-1]<h[b-1] and dp[a-1]==float("INF"):
      sum=sum+1
      dp[a-1]=0
    elif h[b-1]<h[a-1] and dp[b-1]==float("INF"):
      sum=sum+1
      dp[b-1]=0

print(n-sum)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
cnt = 0
new = [0 for i in range(N)]
for ab in AB:
    if H[ab[0]-1] < H[ab[1]-1]:
        new[ab[0]-1] += 1
    if H[ab[0] - 1] > H[ab[1] - 1]:
        new[ab[1]-1] += 1
print(new.count(0))

Submission status: Wrong Answer

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

from sys import stdin
from collections import defaultdict


def main():
    N, M = map(int, stdin.readline().split())
    H = list(map(int, stdin.readline().split()))
    AB = [list(map(int, stdin.readline().split())) for _ in range(M)]

    L = defaultdict(lambda: [])
    for ab in AB:
        L[ab[0] - 1].append(ab[1] - 1)
        L[ab[1] - 1].append(ab[0] - 1)

    ans = 0
    for i in range(len(L)):
        set(L[i])
        if len(L[i]) == 0:
            ans += 1
        else:
            flg = True
            for j in L[i]:
                if H[i] <= H[j]:
                    flg = False
                    break
            if flg:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力（N:展望台数、展望台同士を結ぶ道の総数）
N, M = map(int, input().split())
Hi = input().split()
ten_map = {}
for j in range(1, M+1):
   A, B = map(str, input().split())
   if A not in ten_map:
       ten_map[A] = [B]
   elif B not in ten_map[A]:
          ten_map[A].append(B)
   if B not in ten_map:
       ten_map[B] = [A]
   elif A not in ten_map[B]:
       ten_map[B].append(A)
       

# 出力
result = 0
for i in range(1, N+1):
    check = True
    if str(i) in ten_map:
       for j in ten_map[str(i)]:
           if Hi[i-1] <= Hi[int(j)-1]:
               check = False
               break
    if check:
        result += 1
        

print(result)

Submission status: Wrong Answer

Solution code:
n = list(map(int,input().split()))
l = list(map(int,input().split()))
t=0
for i in range(n[1]):
  l1 = list(map(int,input().split()))
  if l[l1[0]-1]>l[l1[1]-1]:
    t+=1
  if l[l1[1]-1]<l[l1[0]-1]:
    t+=1
print(t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
Height = input().split()
AB =[]
for i in range(M):
    C = input().split()
    AB.append(C)

good_loc = []
for j in range(len(AB)):
    if max(AB[j]) not in good_loc:
        good_loc.append(str(max(AB[j])))

print(len(good_loc))

Submission status: Wrong Answer

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

tmp = [0] * N
max = 0

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

for j in range(N):
  if H[j] >= max:
    tmp[j] = 1
  
#tmp[H.index(max(H))] = 1
print(sum(tmp))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=input().split()
r=[]
for i in range(m):
 r.append([])
 r[i]=input().split()
a=[1]*n
for i in range(m):
 if int(h[int(r[i][0])-1])>int(h[int(r[i][1])-1]):
  a[int(r[i][1])-1]="0"
 elif int(h[int(r[i][0])-1])<int(h[int(r[i][1])-1]):
  a[int(r[i][0])-1]="0"
 elif int(h[int(r[i][0])-1])==int(h[int(r[i][1])-1]):
  a[int(r[i][0])-1]=h[int(r[i][1])-1]="0"
print(n-(a.count("0")))

Submission status: Wrong Answer

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

for i in range(M):
    road_list.append(list(map(int,input().split())))
    
print(height_list)
print(road_list)
print(road_list[0])

Submission status: Wrong Answer

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

roads=[]
mountains={}
testM=0
res=0
ways=0
temp=0
sign=False
for i in range(m):
    roads.append(list(map(int,input().split(" "))))
print(n,m,heights,roads)
for j in range(1,n+1):
    if sign:
        print(j-1)
        res+=1
    sign=True
    for k in range(m):
        if  j==roads[k][0]:
            if  heights[roads[k][1]-1]>heights[j-1]:
                sign=False
                break
        elif j==roads[k][1]:
            if  heights[roads[k][1]-1]>heights[j-1]:
                sign = False
                break

print(res)

Submission status: Wrong Answer

Solution code:
n,k=[int(x) for x in input().split()]
obs=[int(x) for x in input().split()]
ans=[[] for x in range(n)]
count=0
for i in range(0,k):
    a,b=[int(s) for s in input().split()]
    ans[a-1].append(b)
    ans[b-1].append(a)
for k in range(0,len(ans)):
    if ans[k]==[]:
        count+=1
    else:
        if k+1>min(ans[k]):
         count+=1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(m):
    road[i] = list(map(int, input().split()))

for j in range(m):
    if H[road[j][0]-1] <= H[road[j][1]-1]:
        ans[road[j][0]-1] = 1
    elif H[road[j][0]-1] == H[road[j][1]-1]:
        ans[road[j][1]-1] = 1

total = sum(ans)
print(n-total)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
H=list(map(int, input().split()))
# A, B = [0]*M, [0]*M

ans = [True]*N
tmp = []

for _ in range(M):
    a, b = map(int, input().split())
    if not a in tmp:
        tmp.append(a)
    if not b in tmp:
        tmp.append(b)
    if H[a-1] > H[b-1]:
        ans[b-1] = False
    elif H[a-1] < H[b-1]:
        ans[a-1] = False
tmp.sort()
for i in range(len(tmp)):
    tmp[i] -= 1
for i in range(N):
    if not i in tmp:
        ans[i] = False
ctr = 0
for i in range(N):
    if ans[i]:
        ctr += 1

print(ctr)

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 _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
result = []
for i in ab:
    if h[i[0]-1] >= h[i[1]-1]:
        result.append(i[1])
    else:
        result.append(i[0])
result = list(set(result))
print(n - len(result))

Submission status: Wrong Answer

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

for i in range(m):
    tmpa,tmpb = map(int,input().split())
    a.append(tmpa)
    b.append(tmpb)
    ab.append((tmpa,tmpb))

ab = list(set(ab))

cnt = 0
kakunin = []
hoge = set()
for v in ab:
    # print(h[v[0]-1],h[v[1]-1])
    if h[v[0]-1] - h[v[1]-1] < 0 and (v[0] not in hoge):
        if v[0] not in kakunin:
            cnt += 1
        # kakunin.append(v[0])
        hoge.add(v[0])
        # print(kakunin)
    elif h[v[0]-1] - h[v[1]-1] == 0:
            cnt += 1

print(n - cnt)

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
    if all([H[j-1] < t for j in graph[i]]):
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

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

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

List = [list(map(int, input().split())) for i in range(M)]
f_list=list(itertools.chain.from_iterable(List))

cnt=0


for i in range(1,N+1):
  if f_list.count(i)==0:
    cnt+=1


ToF = [0] * N

tmp = []

for i in range(0, M):
    tmp1 = List[i][1] - 1
    tmp.append(List[i][1])
    tmp2 = List[i][0] - 1
    diff = h[tmp1] - h[tmp2]
    if diff > 0:
        ToF[List[i][1] - 1] = 1

print(ToF.count(1)+cnt)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
count = 0
vcount = [0]*n
#arr = []
d = {}
for i in range(m):
    a,b = map(int,input().split())
    jk = [a,b]
    jk.sort()
    vcount[a-1] = 1
    vcount[b-1] = 1
    # arr.append([a,b])
    k1 = jk[0]
    k2 = jk[1]
    d.setdefault(k1, [])
    d.setdefault(k2, [])
    flag = 0
    if((jk[0] in d.get(jk[1])) or (jk[1] in d.get(jk[1]))):
        flag = 1
    if(flag==0):

        d[k1].append(k2)
        d[k2].append(k1)
        #arr.append(jk)
    else:
        #arr.remove(jk)
        d[jk[0]].remove(jk[1])
        d[jk[1]].remove(jk[0])
         
#print(d)
for key in d:
    flag = 0
    gg = d.get(key)
    if(gg):
        for i in gg:
            if(h[key-1]<=h[i-1]):
                flag = 1
                break
        if(flag==0):
            #print(key)
            count+=1
#print(count,sum(vcount))
print(count+n-sum(vcount))

Submission status: Wrong Answer

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

num = input().split(" ")

h = input().split(" ")

counter = [True for i in range(int(num[0]))]

for i in range(int(num[1])):
    ab = input().split(" ")
    a = int(ab[0])-1
    b = int(ab[1])-1
    if h[a] > h[b]:
        counter[b] = False
    if h[a] < h[b]:
        counter[a] = False
    if h[a] == h[b]:
        counter[a] = False
        counter[b] = False
        
print(counter.count(True))

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
    else:
        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(B)
#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
    for i in range(len(A))[::-1]:
        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
#        elif B[A[i][0]-1]==1:
#            B[A[i][0]-1]=B[A[i][1]-1]
#        elif B[A[i][1]-1]==1:
#            B[A[i][1]-1]=B[A[i][0]-1]
            
#print(B)
c = collections.Counter(B)
print(c[1]+c[2])

Submission status: Wrong Answer

Solution code:
import itertools
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = 0
list1 = [] #あって    眺めがいい
list2 = [] #ない     道が通ってる
list3 = [x for x in range(1,n+1)]
list4 = []
for i in range(m):
    a,b = map(int,input().split())
    list2.append(a)
    list2.append(b)
    if h[a-1] > h[b-1]:
        list1.append(a)
    else:
        list1.append(b)
list1 = list(set(list1))
for i in range(n):
    if list2[i] not in list3:
        list4.append(list2[i])

print(len(list1)+len(list4))

Submission status: Wrong Answer

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

for i in range(m):
  abinput = list(map(int,input().split()))
  ab.append(abinput)
  ablist += abinput

dokuritu = list(set(range(1,n+1)) - set(ablist))

#print(dokuritu)
  
anslist = []

for i in ab:
  if h[i[0]-1] < h[i[1]-1]:
    anslist.append(i[1])
    if i[0] in anslist:
      anslist.remove(i[0])
  elif h[i[0]-1] > h[i[1]-1]:
    anslist.append(i[0])
    if i[1] in anslist:
      anslist.remove(i[1])
  else:
    pass

#print(set(anslist))
print(len(set(anslist)) + len(dokuritu))