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

def srch(i, end, l, Dst, Lng):
    if Lng[i] != -1 and Lng[i] < l:
        return
    Lng[i] = l
    if i == end:
        return
    if Dst[i] is not None and len(Dst[i]) > 0:
        for c in Dst[i]:
            srch(c, end, l+1, Dst, Lng)

def main():
    istr = sys.stdin.read()
    ilist = []
    for i in istr.splitlines():
        ilist.append(list(map(int,i.split())))
    #print(ilist)
    unum, fnum = ilist[0]

    Dst = [[] for i in range(unum)]
    fnum += 1
    for n in range(1, fnum):
        uid, fid = ilist[n]
        Dst[uid].append(fid)
        Dst[fid].append(uid)
    
    qnum = ilist[fnum][0]
    fnum += 1
    #print("fnum={} qnum={}".format(fnum,qnum))
    for q in range(fnum, (fnum + qnum)):
        id1, id2 = ilist[q]
        Lng = [-1] * (fnum)
        #print("[{}] id1={:2} id2={:2} Dst:{} Lng:{}".format(q,id1, id2, Dst, Lng))
        srch(id1, id2, 0, Dst, Lng)
        if Lng[id2] != -1:
            print("yes")
        else:
            print("no")

if __name__ == '__main__':
    main()

Fixed submission:
import sys

def Grouping(F):
    n = len(F)
    G = [None for i in range(n)]
    for u in range(n):
        if G[u] is None:
            G[u] = u
            S = [u]
            while(len(S) > 0):
                u1 = S.pop()
                for u2 in F[u1]:
                    if G[u2] is None:
                        G[u2] = u
                        S.append(u2)
    return G

def main():
    istr = sys.stdin.read()
    ilist = istr.splitlines()
    unum, fnum = list(map(int,ilist[0].split()))

    F = [[]  for i in range(unum)]
    fnum += 1
    for n in range(1, fnum):
        uid, fid = map(int,ilist[n].split())
        F[uid].append(fid)
        F[fid].append(uid)
    
    G = Grouping(F)

    qnum = int(ilist[fnum])
    fnum += 1
    for q in range(fnum, (fnum + qnum)):
        id1, id2 = map(int,ilist[q].split())
        if G[id1] == G[id2]:
            print("yes")
        else:
            print("no")

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def srch(i, end, l, Dst, Lng):
    if Lng[i] != -1 and Lng[i] < l:
        return
    Lng[i] = l
    if i == end:
        return
    if Dst[i] is not None and len(Dst[i]) > 0:
        for c in Dst[i]:
            srch(c, end, l+1, Dst, Lng)

def main():
    istr = sys.stdin.read()
    ilist = []
    for i in istr.splitlines():
        ilist.append(list(map(int,i.split())))
    #print(ilist)
    unum, fnum = ilist[0]

    Dst = [[] for i in range(unum)]
    fnum += 1
    for n in range(1, fnum):
        uid, fid = ilist[n]
        Dst[uid].append(fid)
        Dst[fid].append(uid)
    
    qnum = ilist[fnum][0]
    fnum += 1
    #print("fnum={} qnum={}".format(fnum,qnum))
    for q in range(fnum, (fnum + qnum)):
        id1, id2 = ilist[q]
        Lng = [-1] * (unum)
        #print("[{}] id1={:2} id2={:2} Dst:{} Lng:{}".format(q,id1, id2, Dst, Lng))
        srch(id1, id2, 0, Dst, Lng)
        if Lng[id2] != -1:
            print("yes")
        else:
            print("no")

if __name__ == '__main__':
    main()

Fixed submission:
import sys

def Grouping(F):
    n = len(F)
    G = [None for i in range(n)]
    for u in range(n):
        if G[u] is None:
            G[u] = u
            S = [u]
            while(len(S) > 0):
                u1 = S.pop()
                for u2 in F[u1]:
                    if G[u2] is None:
                        G[u2] = u
                        S.append(u2)
    return G

def main():
    istr = sys.stdin.read()
    ilist = istr.splitlines()
    unum, fnum = list(map(int,ilist[0].split()))

    F = [[]  for i in range(unum)]
    fnum += 1
    for n in range(1, fnum):
        uid, fid = map(int,ilist[n].split())
        F[uid].append(fid)
        F[fid].append(uid)
    
    G = Grouping(F)

    qnum = int(ilist[fnum])
    fnum += 1
    for q in range(fnum, (fnum + qnum)):
        id1, id2 = map(int,ilist[q].split())
        if G[id1] == G[id2]:
            print("yes")
        else:
            print("no")

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def srch(id1, id2, D, L):
    cnt = 0

    S = [id1]
    while(len(S) > 0):
        u = S.pop()
        #print("cnt:{} id2:{} u:{} D:{} S:{}".format(cnt, id2, u, D[u], S))
        if L[u] == -1:
            L[u] = cnt
            cnt += 1
            if u == id2:
                return
            if D[u] is not None:
                A = D[u][:]
                while(len(A)):
                    u1 = A.pop()
                    if L[u1] == -1:
                        S.append(u1)
    

def main():
    istr = sys.stdin.read()
    ilist = []
    for i in istr.splitlines():
        ilist.append(list(map(int,i.split())))
    #print(ilist)
    unum, fnum = ilist[0]

    Dst = [[] for i in range(unum)]
    fnum += 1
    for n in range(1, fnum):
        uid, fid = ilist[n]
        Dst[uid].append(fid)
        Dst[fid].append(uid)
    
    qnum = ilist[fnum][0]
    fnum += 1
    #print("fnum={} qnum={}".format(fnum,qnum))
    for q in range(fnum, (fnum + qnum)):
        id1, id2 = ilist[q]
        F = [-1] * (unum)
        #print("\n[{}] id1={:2} id2={:2} D:{}".format(q,id1, id2, Dst))
        srch(id1, id2, Dst, F)
        if F[id2] != -1:
            print("yes")
        else:
            print("no")

if __name__ == '__main__':
    main()

Fixed submission:
import sys

def Grouping(F):
    n = len(F)
    G = [None for i in range(n)]
    for u in range(n):
        if G[u] is None:
            G[u] = u
            S = [u]
            while(len(S) > 0):
                u1 = S.pop()
                for u2 in F[u1]:
                    if G[u2] is None:
                        G[u2] = u
                        S.append(u2)
    return G

def main():
    istr = sys.stdin.read()
    ilist = istr.splitlines()
    unum, fnum = list(map(int,ilist[0].split()))

    F = [[]  for i in range(unum)]
    fnum += 1
    for n in range(1, fnum):
        uid, fid = map(int,ilist[n].split())
        F[uid].append(fid)
        F[fid].append(uid)
    
    G = Grouping(F)

    qnum = int(ilist[fnum])
    fnum += 1
    for q in range(fnum, (fnum + qnum)):
        id1, id2 = map(int,ilist[q].split())
        if G[id1] == G[id2]:
            print("yes")
        else:
            print("no")

if __name__ == '__main__':
    main()