Buggy python submission (verdict: Runtime Error):
import sys

def dfs(s, t):
    global V, d
    d[s] = 1

    if t in V[s]:
        return True

    for v in V[s]:
        if d[v] == 0:
            if dfs(v, t):
                return True

    return False

lines = sys.stdin.readlines()
n, m = map(int, lines[0].split())
V = [[] for _ in range(n)]
for i in range(1, m + 1):
    c = map(int, lines[i].split())
    V[c[0]].append(c[1])
    V[c[1]].append(c[0])

q = int(lines[m + 1])
for i in range(m + 2, m + q + 2):
    c = map(int, lines[i].split())
    d = [0] * (n)
    if dfs(c[0], c[1]):
        print "yes"
    else:
        print "no"

Fixed submission:
def bfs(i, c):
    global V, C

    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Runtime Error):
import sys

def dfs(s, t):
    global V, d
    d[s] = 1

    if t in V[s]:
        return True

    for v in V[s]:
        if d[v] == 0:
            if dfs(v, t):
                return True

    return False

lines = sys.stdin.readlines()
n, m = map(int, lines[0].split())
V = [[] for _ in range(n)]
for i in range(1, m + 1):
    c = map(int, lines[i].split())
    V[c[0]].append(c[1])
    V[c[1]].append(c[0])

q = int(lines[m + 1])
for i in range(m + 2, m + q + 2):
    c = map(int, lines[i].split())
    d = [0] * (n)
    if dfs(c[0], c[1]):
        print "yes"
    else:
        print "no"

Fixed submission:
def bfs(i, c):
    global V, C

    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Runtime Error):
import sys

def dfs(s, t):
    global V, d

    if t in V[s]:
        return True

    d[s] = 1
    for v in V[s]:
        if d[v] == 0:
            if dfs(v, t):
                return True

    return False

lines = sys.stdin.readlines()
if lines[0] == "In preparation.":
    print "In preparation."

n, m = map(int, lines[0].split())
V = [[] for _ in range(n)]
for i in range(1, m + 1):
    c = map(int, lines[i].split())
    V[c[0]].append(c[1])
    V[c[1]].append(c[0])

q = int(lines[m + 1])
for i in range(m + 2, m + q + 2):
    c = map(int, lines[i].split())
    d = [0] * (n)
    if dfs(c[0], c[1]):
        print "yes"
    else:
        print "no"

Fixed submission:
def bfs(i, c):
    global V, C

    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Runtime Error):
import sys

def dfs(s, t):
    global V, d

    if t in V[s]:
        return True

    d[s] = 1
    for v in V[s]:
        if d[v] == 0:
            if dfs(v, t):
                return True

    return False

lines = sys.stdin.readlines()
n, m = map(int, lines[0].split())
V = [[] for _ in range(n)]
for i in range(1, m + 1):
    s, t = map(int, lines[i].split())
    V[s].append(t)
    V[t].append(s)

q = int(lines[m + 1])
for i in range(m + 2, m + q + 2):
    s, t = map(int, lines[i].split())
    d = [0] * (n)
    if dfs(s, t):
        print "yes"
    else:
        print "no"

Fixed submission:
def bfs(i, c):
    global V, C

    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Runtime Error):
def dfs(s, t):
    global V, d

    if t in V[s]:
        return True

    d[s] = 1
    for v in V[s]:
        if d[v] == 0:
            if dfs(v, t):
                return True

    return False

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
for _ in range(m):
    s, t = map(int, raw_input().split())
    V[s].append(t)
    V[t].append(s)

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    d = [0] * (n)
    if dfs(s, t):
        print "yes"
    else:
        print "no"

Fixed submission:
def bfs(i, c):
    global V, C

    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Time Limit Exceeded):
def cover(V, i):
    for j in range(i + 1, len(V)):
        if V[i] & V[j]:
            V.append(V[i] | V[j])
            del V[j], V[i]
            return True

n, m = map(int, raw_input().split())
V = []
for _ in range(m):
    v = set(map(int, raw_input().split()))
    V.append(v)

flag = True
while flag:
    flag = False
    for i in range(len(V)):
        if cover(V, i):
            flag = True
            break

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    flag = True
    for v in V:
        if s in v:
            if t in v:
                print "yes"
            else:
                print "no"
            flag = False
            break
    if flag:
        print "no"

Fixed submission:
def bfs(i, c):
    global V, C

    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Time Limit Exceeded):
def cover(V, i):
    for j in range(i + 1, len(V)):
        if V[i] & V[j]:
            V[i] |=  V[j]
            del V[j]
            return True

n, m = map(int, raw_input().split())
V = []
for _ in range(m):
    v = set(map(int, raw_input().split()))
    V.append(v)

flag = True
while flag:
    flag = False
    for i in range(len(V)):
        if cover(V, i):
            flag = True
            break

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    flag = True
    for v in V:
        if s in v:
            if t in v:
                print "yes"
            else:
                print "no"
            flag = False
            break
    if flag:
        print "no"

Fixed submission:
def bfs(i, c):
    global V, C

    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Runtime Error):
def dfs(i, c):
    global V, C

    if C[i] == -1:
        C[i] = c
    else:
        return

    for v in V[i]:
        dfs(v, c)

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        dfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"

Fixed submission:
def bfs(i, c):
    global V, C

    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"