Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python3

import sys
from collections import defaultdict
from math import gcd
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def formatting(a, b):
    if a == 0:
        return (0, 1)
    g = gcd(a, b)
    a //= g
    b //= g

    if a < 0:
        return (-a, -b)

    return a, b


MOD = pow(10, 9) + 7

N = int(readline())
m = map(int, read().split())
A, B = zip(*zip(m, m))

zz = 0
odd = defaultdict(int)
even = defaultdict(int)

for a, b in zip(A, B):
    if a == b == 0:
        zz += 1
        continue
    a, b = formatting(a, b)
    if b <= 0:
        odd[(a, b)] += 1
    else:
        even[(b, -a)] += 1
        odd[(b, -a)] += 0

ans = zz
k = 1

for key, cnt0 in odd.items():
    cnt1 = even[key]
    acc = pow(2, cnt0, MOD) + pow(2, cnt1, MOD)
    k = k * (acc - 1) % MOD

ans += k - 1
print(ans % MOD)

Fixed submission:
import sys
from collections import deque
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M = map(int, readline().split())
graph = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int1, readline().split())
    graph[A].append(B)
    graph[B].append(A)
ans = [None] * (N)

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

que = deque([0])

while len(que) > 0:
    acc = que.popleft()
    for connected in graph[acc]:
        if visited[connected]:
            continue

        ans[connected] = acc + 1
        visited[connected] = True
        que.append(connected)

if sum(visited) == len(visited):
    print("Yes")
    for sign in ans[1:]:
        print(sign)
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M = map(int, readline().split())
graph = [[0] * N for _ in range(N)]
for i in range(M):
    A, B = map(int1, readline().split())
    graph[A][B] = 1
    graph[B][A] = 1
ans = [None] * (N)

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

que = deque([0])

while len(que) > 0:
    acc = que.popleft()
    for i, pos in enumerate(graph[acc]):
        if pos == 0 or visited[i]:
            continue

        ans[i] = acc + 1
        visited[i] = True
        que.append(i)

if sum(visited) == len(visited):
    print("Yes")
    for sign in ans[1:]:
        print(sign)
else:
    print("No")

Fixed submission:
import sys
from collections import deque
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M = map(int, readline().split())
graph = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int1, readline().split())
    graph[A].append(B)
    graph[B].append(A)
ans = [None] * (N)

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

que = deque([0])

while len(que) > 0:
    acc = que.popleft()
    for connected in graph[acc]:
        if visited[connected]:
            continue

        ans[connected] = acc + 1
        visited[connected] = True
        que.append(connected)

if sum(visited) == len(visited):
    print("Yes")
    for sign in ans[1:]:
        print(sign)
else:
    print("No")