Please help me to identify the reason of SIGSEGV error for this code

This code is the answer to PERCAPTA

from sys import setrecursionlimit
setrecursionlimit(10 ** 9)


def dfs(u):
    if v[u]:
        return
    v[u] = True
    p.append(u + 1)
    for x in graph[u]:
        dfs(x)

for _ in range(int(input())):
    n,m=map(int, input().split())
    cap=list(map(int, input().split()))
    pop=list(map(int, input().split()))
    ratio=[cap[i]//pop[i] for i in range(n)]
    graph=[[] for _ in range(n)]
    for _ in range(m):
        u,v=map(int, input().split())
        graph[u-1].append(v-1)
        graph[v-1].append(u-1)

    maxratio=max(ratio)
    v=[True for i in range(n)]
    for i in range(n):
        if ratio[i]==maxratio:
            v[i]=False
    ans=[]
    p=[]
    for u in range(n):
        if not v[u]:
            dfs(u)
            if len(p)>len(ans):
                ans=p
            p=[]
    print(len(ans))
    print(*ans)
v=[True for i in range(m)]

Change m to n and you will get correct answer.

1 Like

@ameybhavsar thank you for helping, but i still get the same error, anything else please :pray:.

I just submitted the code with the given modification and it says Correct Answer.
Submission

2 Likes

@ameybhavsar thanks again. Great it worked … BUT I was submitting solution with PYPY3 and that was the culprit behind the error. Generally python 3 solutions get accepted in PYPY3. Any knowledge why this was causing the error?