alexjercan/bugnet huggingface dataset:
Problem p02684 (Python) — buggy submission, verdict: Runtime Error

N, K = map(int, input().split())
A_i = list(map(int, input().split()))

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1
    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

if cycle != 0:
    K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)


Error: 0

Fixed submission:

N, K = map(int, input().split())
A_i = list(map(int, input().split()))

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1

    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)
Problem p02684 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    path = [-1] * N * 2
    idx = 0
    visited = [False] * N
    cur = 0
    loop = -1
    while K:
        K -= 1
        if loop == -1 and visited[cur]:
            loop = idx - path.index(cur)
            K %= loop
        path[idx] = cur
        visited[cur] = True
        cur = A[cur] - 1
        idx += 1
    print(cur + 1)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    path = [-1] * N * 2
    idx = 0
    visited = [False] * N
    cur = 0
    while K:
        if visited[cur]:
            loop = idx - path.index(cur)
            K %= loop
        path[idx] = cur
        visited[cur] = True
        cur = A[cur] - 1
        K -= 1
        idx += 1
    print(cur + 1)


if __name__ == "__main__":
    main()
Problem p02684 (Python) — buggy submission, verdict: Runtime Error

N, K = map(int, input().split())
A = list(map(int, input().split()))

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

cnt = 1
prev = 1
while cnt <= K:
    a = A[prev - 1]

    if a in vis:
        c = town2cnt[a]

        rem = K - cnt
        num_loop = cnt - c

        r = rem % num_loop
        print(cnt2town[c + r])

        exit()

    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)

    prev = a
    cnt += 1


print(a)


Error: 0

Fixed submission:

N, K = map(int, input().split())
A = list(map(int, input().split()))

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

for a in A:
    if a in vis:
        c = town2cnt[a]
        rem = K - cnt
        num_loop = cnt - c

        k = rem % num_loop
        print(cnt2town[c + k + 1])
        exit()

    if cnt == K:
        print(a)
        exit()

    cnt += 1
    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)
Problem p02684 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    R = [False] * (N + 1)
    D = []

    p = 1

    while True:
        if R[p]:
            break
        D.append(p)
        R[p] = True
        p = A[p - 1]

    m = D.index(p)
    c = len(D) - m

    if K <= m:
        print(D[K])
    else:
        print(D[m + (K - m) % c])


if __name__ == "__main__":
    main()


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02684/Python/s669353976.py", line 31, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02684/Python/s669353976.py", line 27, in main
    print(D[m + K - m] % c)
IndexError: list index out of range


Fixed submission:

#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    R = [False] * (N + 1)
    D = []

    p = 1

    while True:
        if R[p]:
            break
        D.append(p)
        R[p] = True
        p = A[p - 1]

    m = D.index(p)
    c = len(D) - m

    if K <= m:
        print(D[K])
    else:
        print(D[m + K - m] % c)


if __name__ == "__main__":
    main()
Problem p02684 (Python) — buggy submission, verdict: Runtime Error

N, K = map(int, input().split())
A = list(map(int, input().split()))

flag = [False] * N
counted = [1]

nextT = A[0]
flag[0] = True
for x in range(N):
    if flag[nextT - 1] is False:
        counted.append(nextT)
        flag[nextT - 1] = True
        nextT = A[nextT - 1]
    else:
        break
before_loop_len = counted.index(nextT)
loop_len = x - before_loop_len + 1

if K <= before_loop_len:
    print(counted[K])
else:
    checkK_prep = K - before_loop_len
    checkK = checkK_prep % loop_len
    print(counted[before_loop_len + checkK])


Error: 0

Fixed submission:

N, K = map(int, input().split())
A = list(map(int, input().split()))

loop_checker = {}
before_loop_len = 0
loop_len = 0

count = 2
now = 0
while True:
    if A[now] in loop_checker.values():
        before_loop_len = loop_checker[A[now]]
        loop_len = count - before_loop_len - 1
        break
    else:
        loop_checker[count - 1] = A[now]
        now = A[now] - 1
        count += 1

if K <= before_loop_len:
    print(loop_checker[K])
else:
    checkK_prep = K - before_loop_len
    checkK = checkK_prep % loop_len
    print(loop_checker[before_loop_len + checkK])
Problem p02684 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque
from sys import stdin


def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    As = [int(x) for x in stdin.readline().rstrip().split()]
    pos = 1
    a = [False] * N
    a[0] = True
    tmp = deque([pos])
    for _ in range(K):
        pos = As[pos - 1]
        if a[pos - 1]:
            idx_s = tmp.index(pos)
            break
        a[pos - 1] = True
        tmp.append(pos)
    else:
        print(list(tmp)[-1])
        return

    K = K - idx_s
    tmp = list(tmp)
    print(tmp[idx_s:][K % (len(tmp) - idx_s)])


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

from collections import deque
from sys import stdin


def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    As = [int(x) for x in stdin.readline().rstrip().split()]
    pos = 1
    tmp = deque([pos])
    for _ in range(K):
        pos = As[pos - 1]
        if pos in tmp:
            idx_s = tmp.index(pos)
            break
        tmp.append(pos)
    else:
        print(list(tmp)[-1])
        return

    K = K - idx_s
    tmp = list(tmp)
    print(tmp[idx_s:][K % (len(tmp) - idx_s)])


if __name__ == "__main__":
    main()
Problem p02684 (Python) — buggy submission, verdict: Time Limit Exceeded

#!/usr/bin/env python3

import numpy as np


# def input():
#     return sys.stdin.readline().rstrip()


def main():
    n, k = map(int, input().split())

    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        # dp[h] = dp[h - 1][dp[h - 1]]
        dp[h] = np.take(dp[h - 1], dp[h - 1])

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)


main()


Error: TLE

Fixed submission:

#!/usr/bin/env python3

import numpy as np


# def input():
#     return sys.stdin.readline().rstrip()


def main():
    n, k = map(int, input().split())

    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        for j in range(len(dp[0] + 1)):
            dp[h][j] = dp[h - 1][dp[h - 1][j]]

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)


main()
Problem p02684 (Python) — buggy submission, verdict: Runtime Error

N, K = map(int, input().split(" "))
A = [i for i in map(int, input().split(" "))]

hist = [-1 for i in range(N)]
route = []
loop = []

jump = 0
cur = A[0] - 1
route.append(0)
hist[0] = jump
while hist[cur] == -1:
    jump = jump + 1
    route.append(cur)
    hist[cur] = jump
    cur = A[cur] - 1

loop = route[hist[cur] :]

# print(cur, hist, route, loop)

if K < len(route):
    print(route[K] + 1)
else:
    K = K - len(route)
    # print(K)
    K = K % len(loop)
    # print(K)
    print(loop[K] + 1)


Error: WA

Fixed submission:

N, K = map(int, input().split(" "))
A = [i for i in map(int, input().split(" "))]

hist = [0 for i in range(N)]
route = []
loop = []

jump = 1
cur = A[0] - 1
route.append(0)
hist[0] = jump
while hist[cur] == 0:
    jump = jump + 1
    route.append(cur)
    hist[cur] = jump
    cur = A[cur] - 1

loop = route[cur:]

if K < len(route):
    print(route[K] + 1)
else:
    K = K - len(route) - 1
    K = K % len(loop)
    print(loop[K] + 1)
Problem p02684 (Python) — buggy submission, verdict: Runtime Error

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    went = [0] * N
    went[0] = 1
    Flag = True
    check = [0]
    cnt = 1
    now = 0
    while Flag and (cnt <= K + 1):
        now = A[now] - 1
        if went[now] == 1:
            ind = check.index(now)
            if ind == 0:
                cnt = len(check)
            else:
                cnt = len(check) - ind

            Flag = False
        else:
            check.append(now)
            went[now] = 1
            cnt += 1
            continue

    if len(check) > K:
        print(check[K] + 1)
    else:
        if ind == 0:
            K = K % cnt
            print(check[K] + 1)
        else:
            ind -= 1
            K = (K - ind - 1) % cnt
            print(check[ind + K + 1] + 1)


if __name__ == "__main__":
    main()


Error: 0

Fixed submission:

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    went = [0] * N
    went[0] = 1
    Flag = True
    check = [0]
    cnt = 1
    now = 0
    while Flag and (cnt <= K):
        now = A[now] - 1
        if went[now] == 1:
            ind = check.index(now) - 1
            cnt = cnt - ind - 1
            Flag = False
        else:
            check.append(now)
            went[now] = 1
            cnt += 1
            continue
    if len(check) >= K:
        print(check[K] + 1)
    else:
        K = (K - ind) % cnt
        print(check[ind + K] + 1)


if __name__ == "__main__":
    main()
Problem p02684 (Python) — buggy submission, verdict: Runtime Error

import sys


sys.setrecursionlimit(10**6)


def dfs(v):
    path.append(v)
    visited[v] = 1
    nv = A[v]
    if visited[nv] == 1:
        return nv
    return dfs(nv)


N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
visited = [0] * N
path = []
cycle_start = dfs(0)
cycle_len = len(path) - path.index(cycle_start)
head_len = len(path) - cycle_len
if K <= head_len:
    print(path[K] + 1)
else:
    K -= head_len
    print(path[head_len + K % cycle_len] + 1)


Error: 0

Fixed submission:

def dfs(v):
    path.append(v)
    visited[v] = 1
    nv = A[v]
    if visited[nv] == 1:
        return nv
    return dfs(nv)


N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
visited = [-1] * N
path = []
cycle_start = dfs(0)
cycle_len = len(path) - path.index(cycle_start)
head_len = len(path) - cycle_len
if K <= head_len:
    print(path[K] + 1)
else:
    K -= head_len
    print(path[head_len + K % cycle_len] + 1)
Problem p02684 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a = {i + 1: int(val) for i, val in enumerate(input().split())}

    place = 1
    visit = {place}
    place_visits = [place]
    for i in range(k):
        place = a[place]
        if place in visit:
            left = place_visits.index(place)
            return place_visits[left + (k - left) % (i + 1 - left)]
        else:
            visit.add(place)
            place_visits.append(place)

    return place


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


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a = {i + 1: int(val) for i, val in enumerate(input().split())}

    place = 1
    place_goneds = [place]
    i = 0
    loop_start_index = 0
    while i < n:
        place = a[place]
        goned = False
        for j, place_goned in enumerate(place_goneds):
            if place_goned == place:
                loop_start_index = j
                goned = True
                break

        if goned:
            break

        place_goneds.append(place)
        i += 1

    if k < len(place_goneds):
        return place_goneds[k]

    move_cnt = k - loop_start_index
    loop_list = place_goneds[loop_start_index:]
    return loop_list[move_cnt % len(loop_list)]


if __name__ == "__main__":
    print(main())
Problem p02684 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

table = [[0] * n for _ in [0] * 64]
table[0] = a

for i in range(61):
    for j in range(n):
        table[i + 1][j] = table[i][table[i][j]]

ans = 0
for i in range(61, -1, -1):
    if k >> i & 1:
        ans = table[i][ans]
print(ans + 1)


Error: TLE

Fixed submission:

import numpy as np

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

table = np.zeros((64, n), dtype=np.int64)
table[0] = a

for i in range(61):
    for j in range(n):
        table[i + 1][j] = table[i][table[i][j]]

ans = 0
for i in range(61, -1, -1):
    if k >> i & 1:
        ans = table[i][ans]
print(ans + 1)
Problem p02684 (Python) — buggy submission, verdict: Runtime Error

import sys

readline = sys.stdin.buffer.readline


def solver(N, K, A):
    i = 0
    i_list = [0]
    reached = [False for _ in range(N)]

    while True:
        next_i = A[i]

        if reached[next_i]:
            break

        reached[next_i] = True

        i_list.append(next_i)
        i = next_i

    m = i_list.index(next_i)

    if m >= K:
        return i_list[K] + 1

    le = len(i_list) - m
    K -= m
    ind = K % le

    return i_list[m + ind] + 1


def run():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    A = [a - 1 for a in A]

    ans = solver(N, K, A)
    print(ans)


run()


Error: 0

Fixed submission:

N, K = map(int, input().split())
A = list(map(int, input().split()))

B = [A[0]]

for _ in range(1, N + 10):
    b = A[B[-1] - 1]
    if b in B:
        B += [b]
        break
    else:
        B += [b]
        continue

if len(B) >= K:
    print(B[K])
else:
    ind = [i for i, x in enumerate(B) if x == b]

    K = K - ind[0]
    mod = K % (ind[1] - ind[0])

    print(B[ind[0] + mod - 1])
Problem p02684 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().split())
a = list(map(int, input().split()))
rec = [0]
i = 0
flag = [0 for _ in range(n + 1)]
while True:
    if flag[rec[i]] == 0:
        flag[rec[i]] = 1
        rec.append(a[rec[i]] - 1)
    else:
        start = rec.index(a[rec[i]] - 1)
        loop = rec[start:]
        pre = rec[:start]
        break
    i += 1
count = (k - len(pre)) % len(loop)
if k <= len(pre):
    print(pre[k] + 1)
else:
    print(loop[count] + 1)


Error: 0

Fixed submission:

n, k = map(int, input().split())
a = list(map(int, input().split()))
rec = [0]
i = 0
flag = [0 for _ in range(n + 1)]
while True:
    if flag[rec[i]] == 0:
        flag[rec[i]] = 1
        rec.append(a[rec[i]] - 1)
    else:
        start = rec.index(a[rec[i]] - 1)
        loop = rec[start:]
        pre = rec[:start]
        break
    i += 1
count = (k - len(pre)) % len(loop)
if k < len(pre):
    print(loop[k])
else:
    print(loop[count] + 1)
Problem p02685 (Python) — buggy submission, verdict: Runtime Error

n, m, k = [int(t) for t in open(0).read().split()]
mod = 998244353
mem = [0] * max(k + 3, n + 1)
for i in range(k + 2):
    mem[i] = pow(m, i, mod)
c = 1
for i in range(k + 2, n + 1):
    mem[i] = (m * mem[i - 1] - m * c * pow(m - 1, i - k - 2, mod)) % mod
    c = (c * (i - 1) * pow(i - k - 1, -1, mod)) % mod
print(mem[n])


Error: 0

Fixed submission:

n, m, k = [int(t) for t in open(0).read().split()]
mod = 998244353


def solve(n):
    if n <= k + 1:
        return pow(m, n, mod)
    elif n == k + 2:
        return (pow(m, n, mod) + mod - m) % mod
    else:
        return (m * solve(n - 1) - (m - 1) * solve(n - k - 2)) % mod


print(solve(n))
Problem p02685 (Python) — buggy submission, verdict: Time Limit Exceeded

p = 998244353
N, M, K = map(int, input().split())

ans = 0
cmb = 1
for k in range(K + 1):
    ans += M * pow(M - 1, N - k - 1, p) * cmb
    ans %= p
    cmb *= (N - 1 - k) * pow(k + 1, p - 2, p)
    cmb %= p
print(ans)


Error: TLE

Fixed submission:

def cmb(n, r, p):
    return (fac[n] * pow(fac[r], p - 2, p) * pow(fac[n - r], p - 2, p)) % p


p = 998244353
N, M, K = map(int, input().split())
fac = [1] * (N + 1)
for i in range(1, N + 1):
    fac[i] = (fac[i - 1] * i) % p

ans = 0
for k in range(K + 1):
    ans += M * pow(M - 1, N - k - 1, p) * cmb(N - 1, k, p)
    ans %= p
print(ans)
Problem p02687 (Python) — buggy submission, verdict: Runtime Error

s = input()
if s == "ABC":
    print("ARC")
if s == "ARC":
    print("ABC")


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02687/Python/s038660380.py", line 2, in <module>
    ARC = input("The element of S: ")
EOFError: EOF when reading a line


Fixed submission:

ABC = input("The element of S: ")
ARC = input("The element of S: ")
if ABC == "S":
    print("ABC")
if ARC == "S":
    print("ARC")
Problem p02689 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python3
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())

    l = [1] * N
    for i in range(M):
        if H[A[i] - 1] < H[B[i] - 1]:
            l[A[i] - 1] -= 1
        elif H[A[i] - 1] > H[B[i] - 1]:
            l[B[i] - 1] -= 1
        else:
            l[A[i] - 1] -= 1
            l[B[i] - 1] -= 1
    print(l.count(1))


if __name__ == "__main__":
    main()


Error: 0

Fixed submission:

N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for i in range(M):
    A[i], B[i] = map(int, input().split())

ans = 0
for i in range(N):
    count = 0
    good = 0
    for j in range(M):
        if A[j] == i + 1:
            count += 1
            if H[B[j] - 1] < H[i]:
                good += 1
        if B[j] == i + 1:
            count += 1
            if H[A[j] - 1] < H[i]:
                good += 1
    if count == good:
        ans += 1

print(ans)
Problem p02689 (Python) — buggy submission, verdict: Time Limit Exceeded

n, m = map(int, input().split())
li_h = list(map(int, input().split()))
li_route = list()
remove_idx_set = set()

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

    h_a = li_h[a - 1]
    h_b = li_h[b - 1]

    if h_a <= h_b:
        remove_idx_set.add(a - 1)
    if h_a >= h_b:
        remove_idx_set.add(b - 1)
for s in remove_idx_set:
    li_h[s] = 0
print(len([v for v in li_h if v != 0]))


Error: TLE

Fixed submission:

n, m = map(int, input().split())
li_h = list(map(int, input().split()))
li_route = list()
remove_idx_set = set()

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

    h_a = li_h[a - 1]
    h_b = li_h[b - 1]

    if h_a <= h_b:
        if h_a in li_h:
            remove_idx_set.add(a - 1)
    if h_a >= h_b:
        if h_b in li_h:
            remove_idx_set.add(b - 1)
for s in remove_idx_set:
    li_h[s] = 0
print(len([v for v in li_h if v != 0]))
Problem p02689 (Python) — buggy submission, verdict: Time Limit Exceeded

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

good = [True] * N

for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    if H[A] >= H[B]:
        good[B] = False
    if H[A] <= H[B]:
        good[A] = False
print(sum(good))


Error: TLE

Fixed submission:

N, M = map(int, input().split())
H_i = list(map(int, input().split()))
U = [list(map(int, input().split())) for i in range(M)]

high_max = []
ans = 0

for i in range(N):
    Highes = []
    for j in range(M):
        if U[j][0] == i + 1:
            Highes.append(H_i[U[j][1] - 1])
        if U[j][1] == i + 1:
            Highes.append(H_i[U[j][0] - 1])

    if Highes == []:
        high_max.append(0)
    else:
        high_max.append(max(Highes))

for i in range(N):
    if H_i[i] > high_max[i]:
        ans += 1

print(ans)
Problem p02689 (Python) — buggy submission, verdict: Time Limit Exceeded

#!/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 = [0] * N
    for a, b in AB:
        G[a] = max(G[a], H[b])
        G[b] = max(G[b], H[a])

    ans = 0
    for i in range(N):
        if H[i] > G[i]:
            ans += 1

    print(ans)


solve()


Error: TLE

Fixed submission:

#!/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

    ans = 0
    visited = [False] * N
    for start in range(N):
        if visited[start]:
            continue
        nexts = [i for i in range(N) if G[start][i]]
        if all([H[start] > H[next] for next in nexts]):
            ans += 1
            for next in nexts:
                visited[next] = True

    print(ans)


solve()