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 = [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(len(list(gg))!=0):
        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:
from sys import stdin
N,M= list(map(int,stdin.readline().strip().split()))
H=[int(x) for x in input().split()]
road=[]
hig=[]
ans=[]
kari=[]
count=[0]*N
for i in range(M):
    road.append(list(map(int,input().split())))
for i in range(N):#本体先入れ
    hig.append([[H[i],i]])

for i,j in road:
    hig[i-1].append([H[j-1],j-1])
    hig[j - 1].append([H[i - 1],i-1])
    count[i-1]+=1
    count[j-1]+=1
for i in range(N):
    if count[i]!=0:
        hig[i].sort(key=lambda x: x[0])
        ans.append(hig[i][-1][1])
print(len(set(ans)))

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:
from collections import deque
import numpy as np

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

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

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

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ilst = [int(i) for i in input().split()]
tlst = [0]*n
total = 0
for i in range(m):
    List = [int(j) for j in input().split()]
    print(List)
    xlst = []
    for p in List:
        xlst.append(ilst[p-1])
    print(xlst)
    maxIndex = [i for i, x in enumerate(xlst) if x == max(xlst)]
    print(maxIndex)
    if len(maxIndex) >= 2:
        for k in List:
            tlst[k-1] +=1
    else:
        List.pop(maxIndex[0])
        for k in List:
            tlst[k-1] +=1
for x in tlst:
    if x == 0:
        total +=1
print(total)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = [list(map(int, input().split())) for i in range(M)]
s={AB[0][0]}
A = [0]*N
ans = 0
#print(H)
for i in range(M):
    s.add(AB[i][0])
    s.add(AB[i][1])
    #print(AB[i][0]-1, AB[i][1]-1)
    #print(H[AB[i][0]-1], H[AB[i][1]-1])
    if(H[AB[i][0]-1]==H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
        A[AB[i][1]-1] =-1
    elif(H[AB[i][0]-1]<H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
        #print(AB[i][1]-1)
        if(A[AB[i][1]-1] != -1):
            A[AB[i][1]-1] =1
    else:
        A[AB[i][1]-1] =-1
        if(A[AB[i][0]-1]!=-1):
            A[AB[i][1]-1] =1
#print(A)
#print(s)
ans = A.count(1)
ans += N-len(s)


print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
path = []
for i in range(m):
  a, b = map(int, input().split())
  path.append([a, b])
oblist = []
for j in range(n):
  connect = []
  for k in range(m):
    plist = path[k]
    if plist[0] == (j + 1):
      connect.append(plist[1])
    elif plist[1] == (j + 1):
      connect.append(plist[0])
  oblist.append(connect)
goodob = 0
for l in range(n):
  maxh = h[l]
  if len(oblist[l]) == 0:
    continue
  if max(oblist[l]) < maxh:
    goodob += 1
print(goodob)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
good = []
tmp = []

for i in range(m):
  a,b = map(int,input().split())
  tmp.append(a)
  tmp.append(b)
  a_num = h[a-1]
  b_num = h[b-1]
  if a_num > b_num:
    good.append(a)
    if b in good:
      good.remove(b)
  elif b_num > a_num:
    good.append(b)
    if a in good:
      good.remove(a)

      
result = len(set(good))

if (n-len(set(tmp))) > 0:
  result += n-len(set(tmp))
  
print(result)

Submission status: Wrong Answer

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

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

r = [0]
for i in range(n):
    r.append(set())

for i in range(m):
    a, b = map(int, input().split())
    r[a].add(b)
    r[b].add(a)

ans = 0
for i in range(1, n+1):
    if len(r[i]) == 0:
        ans += 1
        continue
    hmax = h[i-1]
    for j in r[i]:
        flag = False if h[j-1] == h[i-1] else True
        hmax = max(h[j-1], hmax)
    if hmax == h[i-1] and flag: ans += 1

print(ans)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
H = list(map(int, input().split()))
adj = defaultdict(set)
for i in range(M):
    a, b = map(int, input().split())
    adj[a-1].add(H[b-1])
    adj[b-1].add(H[a-1])
ans = 0
for i in range(N):
    adj[H[i]].add(-1)
    if H[i] > max(adj[H[i]]):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
List = []
List2 = []
for i in range(M):
  A,B = map(int,input().split())
  tmpA = H[A-1]
  tmpB = H[B-1]
  if(tmpA > tmpB):
    List.append(A)
  elif(tmpB > tmpA):
    List.append(B)
  List2.append(A)
  List2.append(B)
List = list(set(List))
List2 = list(set(List2))
print(str(len(List) + (N - len(List2))))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
H = list(map(int, input().split()))
loadJ = []
kekka = [True] * N
for i in range(M):
    temp = list(map(int, input().split()))
    loadJ.append(temp)
    
    if H[temp[0] - 1] < H[temp[1] - 1]:
        kekka[temp[0] - 1] = False
    
    if H[temp[1] - 1] < H[temp[0] - 1]:
        kekka[temp[1] - 1] = False

print(kekka.count(True))

Submission status: Wrong Answer

Solution code:
def ma(li):
    # ループごとにifで大小比較
    max_num = 0
    for i in li:
        if max_num < i:
            max_num = i
    return max_num

def appen(li,yousa):
    li.append(yousa)
    return li
    
def main():
    res=0
    n,m=map(int,input().split())
    h=list(map(int,input().split()))
    
    a=[list(map(int,input().split())) for i in range(m)]
    f=[]
    for i in range(n):
        f.append([0])
    for i in a:
        f[i[0]-1].append(h[i[1]-1])
        f[i[1]-1].append(h[i[0]-1])
    p=-1
    for i in f:
        p+=1
        if len(i)==1:
            res+=1
        elif ma(i)<h[p]:
            res+=1
        else:
            continue

    print(res)

Submission status: Wrong Answer

Solution code:
def main():
    numOftenboudai, numOfLoad = map(int, input().split())
    takasaMap = list(map(int, input().split()))
    startArray = []
    pathArray = []
    goodArray = []

    for i in range(numOfLoad):
        start, end = map(int, input().split())
        startArray.append(start)
        if takasaMap[start - 1] < takasaMap[end - 1]:
            goodArray.append(end)
        if "{}:{}".format(start, end) in pathArray:
            goodArray.append(end)
        pathArray.append("{}:{}".format(start, end))

    result = set(goodArray)
    minus = 0
    for x in result:
        if x in startArray:
            minus = minus + 1
    test = len(result) - minus
    print(test)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

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

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

    if (a_int <= b_int):
        l[b - 1] = 1
       
cnt = 0
for k in range(0, len(l)):
    if(l[k]==1):
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
listH=list(map(int,input().split()))
listN=list(range(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
  else:
    listN[A-1]=-1
    listN[B-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 = input().split()
if (M > 0):
  # N本分入る．
  arr = []
  for i in range(M):
    A, B = map(int, input().split())
    if int(H[A-1]) > int(H[B-1]):
      arr.append(H[A-1])
    else:
      arr.append(H[B-1])

  print(len(list(set(arr))))
else:
  print(len(H))

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()))
A_B = [list(map(int, input().split())) for i in range(M)]
cnt = 0
for i in range(1, N+1):
    tmp_list = []
    for j in A_B:
        if i in j:
            tmp_list.append([s for s in j if s != i])
    if len(tmp_list) == 0:
        cnt+=1
        continue
    partner = list(sum(tmp_list, []))
    # partner = [k for k in partner if k != i]
    # partner = partner.remove(i)
    if all([l < i for l in partner]):
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

H = input().split()
if (M > 0):
  # N本分入る．
  arr = []
  for i in range(M):
    A, B = map(int, input().split())
    if int(H[A-1]) > int(H[B-1]):
      arr.append(H[A-1])
    else:
      arr.append(H[B-1])

  print(len(list(set(arr))))
else:
  print(len(H)-1)

Submission status: Wrong Answer

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

cnt = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if h[a] > h[b]:
        if cnt[a] == 2:
            continue
        cnt[a] = 1
        cnt[b] = 2
    else:
        if cnt[b] == 2:
            continue
        cnt[b] = 1
        cnt[a] = 2
ans = 0
for i in cnt:
    if i == 1:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
H = list(map(int,input().split()))
List = []
List2 = []
List3 = []
for i in range(m):
    a,b = map(int,input().split())
    List3.append(a)
    List3.append(b)
    if not (a,b) in List2:
        if H[a-1] > H[b-1]:
            List.append(a)
            List2.append(b)
        elif H[a-1] < H[b-1]:
            List.append(b)
            List2.append(a)
    
ans = len(set(List)) + n - len(set(List3))

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = (int(x) for x in input().split())

B = []
A = list(int(x) for x in input().split())

for i in range(m):
    j, k = (int(x) for x in input().split())
    C = [j, k]
    B.append(C)

count = 0
#1からnまでの展望台を選ぶ
for i in range(1, n + 1):
    #つながっている展望台の組み合わせを選ぶ
    D = []
    for l in B:
        #その組み合わせを分解して新しいリストに入れる
        if i in l:
            for a in l:
                D.append(a)
        else:
            pass
    b = set(D)
    apple = list(b)
    if len(apple) == 0:
        count += 1
        break
    else:
        apple.remove(i)
        E = []
        for cat in apple:
            dog = A[cat - 1]
            E.append(dog)
        if A[i - 1] > max(E):
            count += 1
        else:
            pass
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = input().split()
n= int(N[0])
m = int(N[1])
way = np.zeros(n)
count = 0
h = input().split()
ans = 0
w =0
r = np.zeros(n)

for j in range(m):
    a = input().split()
    b = int(a[0])
    c = int(a[1])
    if h[b-1]>h[c-1]:
        r[b-1] += 1
        r[c-1] = -1000000
    elif h[c-1]>h[b-1]:
        r[c-1] += 1
        r[b-1] = -1000000
    else:
        r[b-1] = -1000000
        r[c-1] = -1000000
print(np.count_nonzero(r>=0))

Submission status: Wrong Answer

Solution code:
def road():
    n, m = map(int, input().split())
    high = list(map(int, input().split()))
    node = [0] * (m * 2)
    cnt = 0
    good = []

    for i in range(0, 2 * m - 1, 2):
        node[i], node[i + 1] = map(int, input().split())

    for j in range(1, n + 1):
        if j not in node:
            cnt += 1
            good.append(j)

    for i in range(0, n):
        if high[i] == max(high):
            good.append(i + 1)
            cnt += 1

    for k in range(1, n + 1):
        flag = 0
        for i in range(0, 2 * m):
            if node[i] == k:
                if i % 2 == 0 and high[k - 1] <= high[node[i + 1] - 1]:
                    flag = 1
                    break
                if i % 2 == 1 and high[k - 1] <= high[node[i - 1] - 1]:
                    flag = 1
                    break

        if (flag == 0) and (k not in good):
            cnt += 1
            good.append(k)

    print(cnt)


road()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)

N, M = map(int, input().split())
H_list = list(map(int, input().split()))
road_list = []


graph_list = [[] for i in range(N)]

for m in range(M):
    A, B = map(int, input().split())
    road_list.append([A, B])

    A -= 1
    B -= 1

    graph_list[A].append(B)
    graph_list[B].append(A)

visited = [False] * N
visited[0] = True
LorS_list = [0] * N

def dfs(current, graph_list):

    global LorS_list
    global visited

    for i in graph_list[current]:
        if visited[i] == False:
            visited[i] = True


            if H_list[current] > H_list[i] and LorS_list[current] != 1:
                LorS_list[current] = 2
                LorS_list[i] = 1

            elif H_list[current] < H_list[i] and LorS_list[i] != 1:
                LorS_list[current] = 1
                LorS_list[i] = 2

            elif H_list[current] == H_list[i]:
                LorS_list[current] = 1
                LorS_list[i] = 1

            dfs(i, graph_list)

dfs(0, graph_list)
ans = LorS_list.count(2) + visited.count(False)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def main():
  N, M = map(int, input().split())
  H = list(map(int, input().split()))
  ob = set(range(1, M+1))
  
  res = []
  for i in range(M):
    A = list(map(int, input().split()))
    ob -= set(A)

    if H[A[0]-1] == H[A[1]-1]:
      continue

    res.append(A[0] if H[A[0]-1] > H[A[1]-1] else A[1])

  print(len(set(res)) + len(list(ob)))

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

res = np.arange(2,n)
res = res.tolist()
for i in range(m):
    if(h_[a_[i][0] - 1] < h_[a_[i][1] - 1]):
        if(a_[i][0] in res):
            res.remove(a_[i][0])
    elif(h_[a_[i][0] - 1] > h_[a_[i][1] - 1]):
        if(a_[i][1] in res):
            res.remove(a_[i][1])
    else:
        if(a_[i][0] in res):
            res.remove(a_[i][0])
        if(a_[i][1] in res):
            res.remove(a_[i][1])

print(len(res))

Submission status: Wrong Answer

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

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

    if (a_int <= b_int):
        l[b - 1] = 1
       
cnt = 0
for k in range(0, len(l)):
    if(l[k]==1):
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

inputs = []
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

obsv = eval(inputs[0].split(" ")[0])
heights = [eval(a) for a in inputs[1].split(" ")]
ways = sorted(set(inputs[2:]))
ways = [[eval(b) for b in a.split(" ")] for a in ways]
no_conn = obsv - len(sorted(set(sum(ways, []))))

ways_inv = [[j,i] for [i,j] in ways]
ways.extend(ways_inv)
ways = sorted(ways)

count = no_conn
start = 1
is_good = []
skiplist = []
s = []
for w in ways:
  if w[0] in skiplist:
    continue
  is_good.append(heights[start-1] > heights[w[1]-1])
  s.append(w[1])
  if start != w[0]:
    if np.all(is_good):
        count += 1
        skiplist.extend(s)
    s = []
    start = w[0]
    is_good = []
if np.all(is_good):
  count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:

import copy

#l2 = copy.copy(l1) 
n,m = map(int,input().split())
h = list(map(int,input().split()))
c = copy.copy(h)
for i in range(m):
    a,b = map(int,input().split())
    #print(a,b,h[a-1],h[b-1])
    if h[a-1] < h[b-1]:
        c[a-1] = c[b-1]
    elif h[a-1] == h[b-1]:
        print(h[a-1])
        c[a-1] = 0
        c[b-1] = 0
    elif h[a-1] > h[b-1]:
        c[b-1] = c[a-1]

#    elif abs(h[a-1]) == h[b-1]:
#        h[a-1] = -h[a-1]
#        h[b-1] = -h[b-1]
t = []
for i in range(n):
    if c[i] != 0:
        t.append(c[i])
#print(t)
s = set(t)
print(len(s))

Submission status: Wrong Answer

Solution code:
NM = input().split()
N = int(NM[0])
M = int(NM[1])
H = list(map(int, input().split()))
IITODAI_FLAG = [0] * N
SYUTUGENTOUDAI =[]
 
for i in range(0, M):
  AB = input().split()
  A = int(AB[0])-1
  B = int(AB[1])-1
  SYUTUGENTOUDAI.append(A)
  SYUTUGENTOUDAI.append(B)
  if H[A]>H[B]:
    IITODAI_FLAG[A]=1
    IITODAI_FLAG[B]=0
  elif H[A]<H[B]:
    IITODAI_FLAG[A]=0
    IITODAI_FLAG[B]=1
  else:
    IITODAI_FLAG[A]=0
    IITODAI_FLAG[B]=0

NOT_SYUTUGENTOUDAI=N-len(list(set(SYUTUGENTOUDAI)))
IITODAI_FLAG_COUNT = IITODAI_FLAG.count(1)


print(NOT_SYUTUGENTOUDAI+IITODAI_FLAG_COUNT)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m= list(map(int,input().split()))
h =  list(map(int,input().split()))
l = [[] for i in range(n)]
s = [0 for i in range(n)]
c = [0 for i in range(n)]

for i in range(m):
  r1,r2 = list(map(int,input().split()))
  l[r1-1].append(r2)
  l[r2-1].append(r1)
  s[r1-1]=1
  s[r2-1]=1

for i in range(n):
  if l[i] == []:
    pass
  else:
    for j in range(len(l[i])):
      if h[l[i][j]-1]<h[i]:
        c[i] = 1
      elif h[l[i][j]-1]>h[i]:
        c[i] = 0
        break
print(s.count(0)+c.count(1))

Submission status: Wrong Answer

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

lisN = [[] for i in range(N)]
for i in range(M):
    inlis = list(map(int, input().split()))
    lisN[max(inlis)-1].append(lisH[min(inlis)-1])

ans = 0
for i in range(N):
    if len(lisN[i])>0:
        if lisH[i] > max(lisN[i]):
            ans += 1
    else :
        ans += 1
print(ans)

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]
   else :
       ten_map[A].append(B)
   if B not in ten_map:
       ten_map[B] = [A]
   else :
       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,M = map(int,input().split())
H = list(map(int,input().strip().split()))
xy=[map(int, input().split()) for _ in range(M)]
x, y = [list(i) for i in zip(*xy)]

list=[0]*N
for i in range(M):
    if H[x[i]-1]<H[y[i]-1]:
        list[x[i]-1]+=1
    else:
        list[y[i]-1]+=1
count=0
for i in range(N):
    if list[i]==0:
        count+=1


print(count)

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][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()))
datas = []
ans = []
for i in range(M):
    datas.append(list(map(int,input().split())))
for data in datas:
    a,b = data
    if H[a-1] > H[b-1]:
        ans.append(a)
    else:
        ans.append(b) 
print(len(set(ans)))

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

root = [0] * n
good = [0] * n
for i in range(m):
    root[ab[i][0]-1] += 1
    root[ab[i][1]-1] += 1
    if h[ab[i][0]-1] < h[ab[i][1]-1]:
        good[ab[i][1]-1] += 1
    else:
        good[ab[i][0]-1] += 1

ans = 0
for i in range(n):
    if root[i] == good[i]:
        ans +=1

print(ans)

Submission status: Wrong Answer

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

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 = []
for v in ab:
    # print(h[v[0]-1],h[v[1]-1])
    if h[v[0]-1] - h[v[1]-1] < 0:
        if v[0] not in kakunin:
            cnt += 1
        kakunin.append(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:
n = list(map(int,input().split()))
m = list(map(int,input().split()))

a = []
kaku = []
for x in range(n[1]) :
    a.append(list(map(int, input().split())))

kaku = [0]* len(m)
cou = 0

for x in range(n[1]):
    if m[a[x][0] -1 ] > m[a[x][1] -1 ]:
        kaku[a[x][0] -1 ] += 1
    else:
        kaku[a[x][0] - 1] -= 1

    if m[a[x][1] -1 ] > m[a[x][0] -1 ]:
        kaku[a[x][1] -1 ] += 1
    else:
        kaku[a[x][1] - 1] -= 1

for x in range(len(m)):
    if kaku[x] >= 0 :
        cou += 1

print(cou)

Submission status: Wrong Answer

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

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

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

    if flag==0:
        tmp[b-1]=-1
    if flag==1:
        tmp[a-1]=-1

cnt=0
for i in range(len(tmp)):
    if tmp[i] >= 0:
        cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
list = [{} for _ in range(N)]
for x in AB:
    if x[1]-1 not in list[x[0]-1].keys():
        list[x[0]-1][x[1]-1] = 1
    if x[0]-1 not in list[x[1]-1].keys():
        list[x[1]-1][x[0]-1] = 1
#print(list)
ans = set()
for n, x in enumerate(list):
    cand = [H[i] for i in x.keys()]+[H[n]]
    #print(cand)
    trial = 0
    flag = 0
    for t in cand:
        if trial < t:
            trial = t
        elif trial == t:
            flag = 1
            break
    if flag == 0:
        ans.add(trial)
print(len(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

G = [[] for i in range(N)]

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

dist = [-1] * N
que = deque()

# 初期条件
result = [i for i in range(N)]
dist[0] = 0
que.appendleft(0)

count = 0

while not not que:
    v = que.pop()    #queから次に移動する頂点を取り出す
    for nv in G[v]:
        # print('v ',v)
        # print('hv ',H[v])
        # print('nv ', nv)
        # print('hnv ',H[nv])

        if dist[nv] != -1:
            if H[v] <= H[nv] and v in result:
                # print('count v:',v)
                # print('count nv :',nv)
                result.remove(v)
                # print(result)
            continue      #発見済み
        if H[v] <= H[nv] and v in result:
            # print('count v:',v)
            # print('count nv :',nv)
            result.remove(v)
            # print(result)
        dist[nv] = dist[v] + 1 #dist[nv]はnvまでの距離なのでインクリメント
        que.appendleft(nv)  #新たに発見した頂点をqueに入れる

for i in result:
    if dist[i] == -1:
        result.remove(i)

print(len(result))

Submission status: Wrong Answer

Solution code:
lis = input().split()
N = int(lis[0])
M = int(lis[1])
H = input().split()
T = list(range(N+1))

for i in range(M):
    R = input().split()
    r1 = int(R[0])
    r2 = int(R[1])
    R1 = r1-1
    R2 = r2-1
    #print("r1=",r1,"r2=",r2)
    if int(H[R1]) >= int(H[R2]):
        if int(r2) in T:
            T.remove(int(r2))
    else:
        if int(r1) in T:
            T.remove(int(r1))

print(len(T) - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

high = np.array([0]*n)
cnt = np.array([0]*n)

for _ in range(m):
    a,b = map(int, input().split())
    if h[a-1] > h[b-1]:
        np.put(high, [a-1],1)
    elif h[a-1] < h[b-1]:
        np.put(high, [b-1],1)
    np.put(cnt, [a-1,b-1],1)

ans = np.count_nonzero(high==1) +np.count_nonzero(cnt==0)

print(ans)