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())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
ans=0
for v in range(1,n+1):
    for u in g[v]: #i番目の展望台から1本の道を通っていけるすべての展望台と高さを比較する
        if arr[u]>=arr[v]:
            break
        else: #i番目の展望台の高さが他のすべての展望台の高さより真に大きければ答えを1増やす
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
H = [0] + list(map(int, input().split()))
A = [0]
B = [0]

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

g = [[] for _ in range(n+1)]
for i in range(m):
    g[A[i]].append(B[i])
    g[B[i]].append(A[i])

ans = 0
for v in range(1, n + 1):
    for u in g[v]: 
        if H[u] >= H[v]:
            break
        else: 
             ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
nm=list(map(int,input().split()))
n=nm[0]
m=nm[1]
h=list(set(map(int,input().split())))
h.sort()
good=[]
ngood=[]

for i in range(m):
  ab=list(map(int,input().split()))
  ab_min=min(ab)  
  if ab_min in h:
     h.remove(ab_min)
  else:
     pass    
else:pass

print(len(h))

Submission status: Wrong Answer

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

m_l = [[0,0]]*m
r_l = [{}]*n
for i in range(m):
  r = list(map(int, input().split()))
  a = r[0] - 1
  b = r[1] - 1

  ral = set([]) if len(r_l[a]) == 0 else r_l[a]
  rbl = set([]) if len(r_l[b]) == 0 else r_l[b]

  ral.add(b)
  rbl.add(a)

  r_l[a] = ral
  r_l[b] = rbl
print(r_l)

cnt = 0
for ni in range(n):
  for r in r_l[ni]:
    if h_a[r] >= h_a[ni]:
      break
  else:
    cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=map(int,input().split())
lis=[]
cou=0
for i in range(M):
    l=list(map(int,input().split()))
    lis.append(l)
for i in H:
    c=0
    cp=0
    cm=0
    for j in lis:
        if i in j:
            c+=1
            if max(j[0], j[1]) == i:
                cp = 1
            else:
                cm = 1
                break
    if c==0:
        cou+=1
    if cp==1 and cm==0:
        cou+=1

print(cou)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=map(int,input().split())
lis=[]
cou=0
for i in range(M):
    l=list(map(int,input().split()))
    lis.append(l)
for i in H:
    c=0
    cp=0
    cm=0
    for j in lis:
        if i in j:
            c+=1
            if max(j[0], j[1]) == i:
                cp = 1
            else:
                cm = 1
    if c==0:
        cou+=1
    if cp==1 and cm==0:
        cou+=1
print(cou)

Submission status: Wrong Answer

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

ans = {}

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

    if h[a - 1] > h[b - 1]:
        ans[b - 1] = False
        h[b - 1] = h[a - 1]
    elif h[a - 1] < h[b - 1]:
        ans[a - 1] = False
        h[a - 1] = h[b - 1]
    else:
        ans[a - 1] = False
        ans[b - 1] = False

print(N - len(ans))

Submission status: Wrong Answer

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

count = 0
for i in range(N):
    if H[i] != 0:
        count+= 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

def main():
    N, M  = list(map(int, input().split()))
    H     = list(map(int, input().split()))
    maxH  = np.zeros(N)

    for itr in range(M):
        A, B = list(map(int, input().split()))
        if H[A- 1] == H[B- 1] :
            maxH[A- 1] = -1
            maxH[B- 1] = -1
        elif H[A- 1] > H[B- 1] :
            if maxH[A- 1] < H[A- 1] :
                maxH[A- 1] = copy.copy(H[A- 1])
            if maxH[B- 1] < H[A- 1] :
                maxH[B- 1] = copy.copy(H[A- 1])
        elif H[A- 1] < H[B- 1] :
            if maxH[A- 1] < H[B- 1] :
                maxH[A- 1] = copy.copy(H[B- 1])
            if maxH[B- 1] < H[B- 1] :
                maxH[B- 1] = copy.copy(H[B- 1])
    
    result = 0
    for itr in range(N):
        if H[itr] == maxH[itr] or maxH[itr] == 0:
            result += 1
    #print(maxH)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

def main():
    N, M  = list(map(int, input().split()))
    H     = list(map(int, input().split()))
    maxH  = np.zeros(N)

    for itr in range(M):
        A, B = list(map(int, input().split()))
        if H[A- 1] == H[B- 1] :
            maxH[A- 1] = -1
            maxH[B- 1] = -1
        elif H[A- 1] > H[B- 1] :
            maxH[A- 1] = copy.copy(H[A- 1])
            maxH[B- 1] = copy.copy(H[A- 1])
        elif H[A- 1] < H[B- 1] :
            maxH[A- 1] = copy.copy(H[B- 1])
            maxH[B- 1] = copy.copy(H[B- 1])
    
    result = 0
    for itr in range(N):
        if H[itr] == maxH[itr] or maxH[itr] == 0:
            result += 1
    #print(maxH)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

def main():
    N, M  = list(map(int, input().split()))
    H     = list(map(int, input().split()))
    maxH  = np.zeros(N)

    for itr in range(M):
        A, B = list(map(int, input().split()))
        if H[A- 1] == H[B- 1] :
            maxH[A- 1] = -1
            maxH[B- 1] = -1
        elif H[A- 1] > H[B- 1] :
            maxH[A- 1] = copy.copy(H[A- 1])
            maxH[B- 1] = copy.copy(H[A- 1])
        elif H[A- 1] < H[B- 1] :
            maxH[A- 1] = copy.copy(H[B- 1])
            maxH[B- 1] = copy.copy(H[B- 1])
    
    result = 0
    for itr in range(N):
        if H[itr] == maxH[itr] or maxH[itr] == 0:
            result += 1
    print(maxH)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

H = list(map(int, input().split()))
D = { i+1: set() for i in range(N) }

for _ in range(M):
    A, B = map(int, input().split())
    D[A].add(B)
    D[B].add(A)

cdt = [1] * N
for d, hs in D.items():
    for h in hs:
        if H[h-1] > H[d-1]:
            cdt[h-1] = 1
            cdt[d-1] = 0
        elif H[h-1] < H[d-1]:
            cdt[h-1] = 0
            cdt[d-1] = 1
        else:
            if cdt[h-1] == 0:
                cdt[d-1] = cdt[h-1]
print(sum(cdt))

Submission status: Wrong Answer

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

result = 0
good_obs = []
for road in roads:
    if road[0] - road[1] > 0:
        good_obs.append(road[0])
    if road[1] - road[0] > 0:
        good_obs.append(road[1])

print(len(set(good_obs)))

Submission status: Wrong Answer

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

result = 0
good_obs = []
for road in roads:
    start = road[0]
    end = road[1]
    start_alt = road[1]
    end_alt = road[0]
    if start - end > 0:
        good_obs.append(start)
    if start_alt - end_alt > 0:
        good_obs.append(start_alt)

print(len(set(good_obs)))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
good = set(range(N))
for _ in range(M):
    a, b = [int(x) - 1 for x in input().split()]
    if H[a] <= H[b]:
        good -= {a}
    if H[a] == H[b]:
        good -= {b}
print(len(good))

Submission status: Wrong Answer

Solution code:
class Peak():
    def __init__(self, inode, hight):
        self.inode = inode
        self.hight = hight
        self.neighbors = []
        self.is_higher = True

    def add(self, node):
        is_exist = False
        for n in self.neighbors:
            if n.inode == node.inode:
                is_exist = True
                break
        if not is_exist:
            if self.hight > node.hight:
                self.is_higher = True
            else:
                self.is_higher = False
            self.neighbors.append(node)

n, m = map(int, input().split())
peaks = [None]*n
hs = [int(h) for h in input().split()]
for _ in range(m):
    a, b = map(int, input().split())
    ap, bp = None, None
    if peaks[a-1]:
        ap = peaks[a-1]
    else:
        ap = Peak(a-1,hs[a-1])
    if peaks[b-1]:
        bp = peaks[b-1]
    else:
        bp = Peak(b-1,hs[b-1])
    ap.add(bp)
    bp.add(ap)
    peaks[a-1], peaks[b-1] = ap, bp
nice = 0
for p in peaks:
    if p and p.is_higher:
        nice += 1
    elif p == None:
        nice += 1
print(nice)

Submission status: Wrong Answer

Solution code:
class Peak():
    def __init__(self, inode, hight):
        self.inode = inode
        self.hight = hight
        self.neighbors = []
        self.is_higher = False

    def add(self, node):
        is_exist = False
        for n in self.neighbors:
            if n.inode == node.inode:
                is_exist = True
                break
        if not is_exist:
            if self.hight > node.hight:
                self.is_higher = True
            else:
                self.is_higher = False
            self.neighbors.append(node)

n, m = map(int, input().split())
peaks = [None]*n
hs = [int(h) for h in input().split()]
for _ in range(m):
    a, b = map(int, input().split())
    ap, bp = None, None
    if peaks[a-1]:
        ap = peaks[a-1]
    else:
        ap = Peak(a-1,hs[a-1])
    if peaks[b-1]:
        bp = peaks[b-1]
    else:
        bp = Peak(b-1,hs[b-1])
    ap.add(bp)
    bp.add(ap)
    peaks[a-1], peaks[b-1] = ap, bp
nice = 0
for p in peaks:
    if p and p.is_higher:
        nice += 1
    elif p == None:
        nice += 1
print(nice)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
hight_list = list(map(int, input().split()))    
roads = []
towers = []
T_H = {}
good_tower = set()
for i in range(1, N + 1):
    T_H[str(i)] = hight_list[i - 1]
    towers.append(str(i))
for j in range(M):
    [A, B] = list(map(str, input().split()))
    roads.append([A, B])

for road in roads:
    a = road[0]
    b = road[1]
    
    if T_H[a] > T_H[b]:
        good_tower.add(a)
        if b in good_tower:
            good_tower.remove(b)
    if T_H[b] > T_H[a]:
        good_tower.add(b)
        if a in good_tower:
            good_tower.remove(a)
    if a in towers:
        towers.remove(a)
    if b in towers:
        towers.remove(b)
print(len(good_tower) + len(towers))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
hight_list = list(map(int, input().split()))    
good_tower = set()
roads_list = []
for j in range(M):
    [A, B] = list(map(int, input().split()))
    roads_list.append([A, B])
for roads in roads_list:
    good_tower.add(max(roads))
    if min(roads) in good_tower:
        good_tower.remove(min(roads))
print(len(good_tower))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
list_n=[]
for i in range(1,n+1):
    list_n.append(i)
    
h=list(map(int,input().split()))
list_s=[]
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]!=h[b-1]:
        s=max(h[a-1],h[b-1])
        list_s.append(s)
    if a in list_n:
        list_n.remove(a)
    if b in list_n:
        list_n.remove(b)
    
    

list_t=list(set(list_s))
list_t+=list_n
print(len(list_t))

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 nesya in range(m)]
k = [1]*n
for route in x:
  h1 = route[0]-1
  h2 = route[1]-1
  if h[h1] < h[h2]:
    k[h1] = 0
  elif h[h1] > h[h2]:
    k[h2] = 0
print(sum(k))

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 nesya in range(m)]
k = [1]*n
for route in x:
  h1 = route[0]-1
  h2 = route[1]-1
  if h[h1] < h[h2]:
    k[h1] = 0
  else:
    k[h2] = 0
print(sum(k))

Submission status: Wrong Answer

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

X = [1]*N
for i in range(M):
    a,b = map(int,input().split())
    x1 = H[a-1]
    x2 = H[b-1]
    if x1 < x2:
        X[a-1] = False
        if X[b-1] != False:
            X[b-1] = True

    else:
        X[b-1] = False
        if X[a-1] != False:
            X[a-1] = True
print(X.count(True))

Submission status: Wrong Answer

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

high = set()
low = set()
lonely = set()

for i in range(M):
	i1, i2 = [int(x) for x in input().split()]
	if H[i1 - 1] != H[i2 - 1]:
		high.add(i2)
		low.add(i1)
	lonely.add(i1)
	lonely.add(i2)

result = len((high - low)) + (N  - len(lonely))
print(result)

Submission status: Wrong Answer

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

high = set()
low = set()
lonely = set()

for i in range(M):
    i1, i2 = [int(x) for x in input().split()]
    if H[i1 - 1] != H[i2 - 1]:
        high.add(i2)
    low.add(i1)
    lonely.add(i1)
    lonely.add(i2)

result = len((high - low)) + (N  - len(lonely))
print(result)

Submission status: Wrong Answer

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

high = set()
low = set()
lonely = set()

for i in range(M):
    i1, i2 = [int(x) for x in input().split()]
    if H[i1 - 1] != H[i2 - 1]:
        high.add(i2)
    low.add(i1)
    lonely.add(i1)
    lonely.add(i2)

result = len((high - low)) + (N  - len(lonely))

Submission status: Wrong Answer

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

high = set()
lonely = set()

for i in range(M):
	i1, i2 = [int(x) for x in input().split()]
	if H[i1 - 1] != H[i2 - 1]:
		high.add(i2)
	lonely.add(i1)
	lonely.add(i2)

result = len(high) + (N  - len(lonely))
print(result)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
# sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
l = readl()
f = [[] for i in range(n)]
for i in range(m):
    a, b = readmi()
    heapq.heappush(f[a - 1], -l[a - 1])
    heapq.heappush(f[a - 1], -l[b - 1])
    heapq.heappush(f[b - 1], -l[a - 1])
    heapq.heappush(f[b - 1], -l[b - 1])
count = 0
for i in range(n):
    if f[i]:
        t = heapq.heappop(f[i])
        if t < -l[i]:
            count += 1
    else:
        count += 1
print(count)

Submission status: Wrong Answer

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

H_t = input()

H = [0]*N

H_M = []

good_count = 0

for i in range(N):
    
    H[i]= int(H_t.split()[i])
    
    H_M.append(set())

#print(H_M)

for j in range(M):
    a, b = map(int, input().split())
     
    tmp_a = H_M[a-1]
    tmp_b = H_M[b-1]
    
    tmp_a.add(b-1)
    tmp_b.add(a-1)
    
    
    H_M[a-1] = tmp_a
    H_M[b-1] = tmp_b


    
for i in range(N):
    flag = True
    h_a = H_M[i]
    #print(h_a)
    
    for n in h_a:
        #print(n)
        
        if H[i] < H[n]: # ひとつでも今の山より高い山があったら
            #print("aa")
            flag = False
            break

    if flag == True:
        good_count += 1

print(good_count)

Submission status: Wrong Answer

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

H_t = input()

H = [0]*N

H_M = []

good_count = 0

for i in range(N):
    
    H[i]= int(H_t.split()[i])
    
    H_M.append(set())

#print(H_M)

for j in range(M):
    a, b = map(int, input().split())
     
    tmp_a = H_M[a-1]
    tmp_b = H_M[b-1]
    
    tmp_a.add(b-1)
    tmp_b.add(a-1)
    
    
    H_M[a-1] = tmp_a
    H_M[b-1] = tmp_b


    
for i in range(N):
    flag = True
    h_a = H_M[i]
    #print(h_a)
    
    for n in h_a:
        #print(n)
        
        if H[i] < H[n]: # ひとつでも今の山より高い山があったら
            #print("aa")
            flag = False

    if flag == True:
        good_count += 1

print(good_count)

Submission status: Wrong Answer

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

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

for j in range(M):
    if H[List[j][0]-1]>H[List[j][1]-1]:
        sup_list[List[j][1]-1]=0
    elif H[List[j][0]-1]==H[List[j][1]-1]:
        sup_list[List[j][0]-1]=0
        sup_list[List[j][1]-1]=0
    else:
        sup_list[List[j][0]-1]=0

print(sup_list)
print(sum(sup_list))

Submission status: Wrong Answer

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

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

for j in range(M):
    if H[List[j][0]-1]>H[List[j][1]-1]:
        sup_list[List[j][1]-1]=0
    elif H[List[j][0]-1]==H[List[j][1]-1]:
        sup_list[List[j][0]-1]=0
        sup_list[List[j][1]-1]=0
    else:
        sup_list[List[j][1]-1]=0
print(sum(sup_list))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def main():
    number_of_observatory,number_of_bridge = map(int,input().split())
    observatory_elevation = list(map(int,input().split()))

    observatory_informaiton_dict = {}
    
    for bridge_number in range(number_of_bridge):
        observatory_1,observatory_2 = map(int,input().split())
        if not observatory_1 in observatory_informaiton_dict:
            observatory_informaiton_dict[observatory_1] = [observatory_2]
        else:
            observatory_informaiton_dict[observatory_1].append(observatory_2)
        
        if not observatory_2 in observatory_informaiton_dict:
            observatory_informaiton_dict[observatory_2] = [observatory_1]
        else:
            observatory_informaiton_dict[observatory_2].append(observatory_1)
    result = 0
    for observatory_informaiton_key,observatory_informaiton_value in observatory_informaiton_dict.items():
        if all([observatory_elevation[observatory-1] < observatory_elevation[observatory_informaiton_key-1] for observatory in observatory_informaiton_value]):
            result += 1
            
    for isolate in range(1,number_of_observatory):
        if not isolate in observatory_informaiton_dict:
            result += 1

    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

j = 1
for j in range(n+1):
    if j in bad:
        pass
    else:
        ans.append(j)
    j += 1
        
print(ans)
print(len(ans)-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N, M = [int(el) for el in input().split()]

hts = [int(el) for el in input().split()]
heights = {}
for i, val in enumerate(hts, start=1):
    heights[i] = val

routes = defaultdict(lambda: set())
for _ in range(M):
    s, d = [int(el) for el in input().split()]
    routes[s].add(d)
    routes[d].add(s)

gd = 0
for src, destinations in routes.items():
    good = True
    for dest in destinations:
        if heights[src] <= heights[dest]:
            good = False
    if good:
        gd += 1
print(gd)

Submission status: Wrong Answer

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

for i in range(len(H_list)):
    iso_list.append(i+1)

good_set = set()

for m in range(M):
    A,B = map(int,input().split())
    
    if A in iso_list:
        iso_list.remove(A)
    if B in iso_list:
        iso_list.remove(B)
    
    if A in good_set:
        good_set.remove(A)
    if B in good_set:
        good_set.remove(B)
    
    if H_list[A-1] > H_list[B-1]:
        good_set.add(A)
    elif H_list[A-1] < H_list[B-1]:
        good_set.add(B)
    
print(len(good_set)+len(iso_list))

Submission status: Wrong Answer

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

for i in range(len(H_list)):
    iso_list.append(i+1)

good_set = set()

for m in range(M):
    A,B = map(int,input().split())
    
    if A in iso_list:
        iso_list.remove(A)
    if B in iso_list:
        iso_list.remove(B)
    
    if A in good_set:
        good_set.remove(A)
    elif B in good_set:
        good_set.remove(B)
    
    if H_list[A-1] > H_list[B-1]:
        good_set.add(A)
    elif H_list[A-1] < H_list[B-1]:
        good_set.add(B)
    
print(len(good_set)+len(iso_list))

Submission status: Wrong Answer

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

#二次元配列から重複を取り除く関数
def get_unique_list(seq) :
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

n, m = map(int, input().split()) # 展望台と道の数
h_list = list(map(int, input().split())) # n個の展望台の標高
# どの展望台とどの展望台を結ぶ道があるかのリスト
plane_load_list = []
for i in range(m) :
    plane_load_list.append(list(map(int, input().split())))

# 同じ道は2回以上判定する必要がないので取り除く
load_list = get_unique_list(plane_load_list)

num = [x for x in range(1, n+1)]
bad = []
for i in range(0, len(load_list)) :
    if load_list[i][0] in bad and load_list[i][1] in bad :
        break
    if h_list[load_list[i][0]-1]<h_list[load_list[i][1]-1] :
        bad.append(load_list[i][0])
    elif h_list[load_list[i][0]-1]>h_list[load_list[i][1]-1] :
        bad.append(load_list[i][1])
    else :
        bad.append(load_list[i][0])
        bad.append(load_list[i][1])

bad_value = list(set(bad))
print(len(num)-len(bad_value))

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline
 
#二次元配列から重複を取り除く関数
def get_unique_list(seq) :
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

n, m = map(int, input().split()) # 展望台と道の数
h_list = list(map(int, input().split())) # n個の展望台の標高
# どの展望台とどの展望台を結ぶ道があるかのリスト
plane_load_list = []
for i in range(m) :
    plane_load_list.append(list(map(int, input().split())))

# 同じ道は2回以上判定する必要がないので取り除く
load_list = get_unique_list(plane_load_list)

num = [x for x in range(1, n+1)]
bad = []
for i in range(0, len(load_list)) :
    if load_list[i][0] in bad and load_list[i][1] in bad :
        break
    if h_list[load_list[i][0]-1]<h_list[load_list[i][1]-1] :
        bad.append(load_list[i][0])
    else :
        bad.append(load_list[i][1])

bad_value = list(set(bad))
print(len(num)-len(bad_value))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*n
for i in range(m):
    x,y=map(int,input().split())
    a[x-1]=l[y-1]
    a[y-1]=l[x-1]
ans=0
for i in range(n):
    if l[i]>a[i]:
        ans+=1 
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int , input().split())
H  = list(map(int , input().split()))
for i in range(M):
  A, B = map(int , input().split())
p = 0
for i in range(1 , N+1):
  q = 0
  C = [0]
  for j in range(M):
    if(A == i):
      b = H[B-1]
      C.append(b)
      q += 1
    elif(B == i):
      a = H[A-1]
      C.append(a)
      q += 1
    else:
      C.append(0) 
  G = max(C)
  if(H[i-1] > G or G==0):
    p += 1
print(p)

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    ans = [True]*n
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        a -= 1
        b -= 1
        if h[a] <= h[b]:
            ans[a] = False
        else:
            ans[b] = False
    print(sum(ans))


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = set()
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].add(h[b-1])
        links[h[b-1]].add(h[a - 1])
    cnt = 0
    # visited = set()
    for k, v in links.items():
        if len(v):
            c = 0
            for j in v:
                if k > j:
                    c += 1
            if c == len(v):
                cnt += 1
        else:
            cnt += 1
    # print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = list()
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].append(h[b-1])
        links[h[b-1]].append(h[a - 1])
    cnt = 0
    # visited = set()
    for k, v in links.items():
        if len(v):
            c = 0
            for j in v:
                if k > j:
                    c += 1
            if c == len(v):
                cnt += 1
        else:
            cnt += 1
    # print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = list()
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].append(h[b-1])
        links[h[b-1]].append(h[a - 1])
    cnt = 0
    c = 0
    # visited = set()
    for k, v in links.items():
        if len(v):
            for j in v:
                if k > j:
                    c += 1
            if c == len(v):
                cnt += 1
            c = 0
        else:
            cnt += 1
    # print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    h = list(map(int, sys.stdin.readline().split()))
    set_h = set()
    links = dict()
    for i in range(1, n + 1):
        links[h[i-1]] = list()
    v = set()
    for i in range(m):
        a, b = map(int, sys.stdin.readline().split())
        links[h[a-1]].append(h[b-1])
        links[h[b-1]].append(h[a - 1])
    cnt = 0
    c = 0
    # visited = set()
    for k, v in links.items():
        if len(v):
            for j in v:
                if k > j:
                    c += 1
            if c == len(v):
                cnt += 1
            c = 0
        else:
            cnt += 1
    print(links)
    print(cnt)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()