Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from collections import deque
    import sys

    n,m =map(int,input().split())
    abl=[[] for i in range(n)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a-1].append(b)
        abl[b-1].append(a)

    an=[0]*(n-1)
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg-1]:
            if an[j-2]==0 and j!=1:
                an[j-2]=itg
                tg.append(j)
            if all(an):
                print('Yes')
                for j in an:
                    print(j)
                sys.exit()

    if all(an):
        print('Yes')
        for j in an:
            print(j)
    else:
        print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from collections import deque
    import sys

    n,m =map(int,input().split())
    abl=[[] for i in range(n)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a-1].append(b)
        abl[b-1].append(a)

    an=[0]*(n-1)
    tg = deque([1])
    wwk =deque([])
    while not(all(an)):
        while len(tg):
            itg = tg.pop()
            for j in abl[itg-1]:
                if an[j-2]==0 and j!=1:
                    an[j-2]=itg
                    wwk.append(j)
                if all(an):
                    print('Yes')
                    for j in an:
                        print(j)
                    sys.exit()
        tg=deque(wwk)
        wwk =deque([])

    if all(an):
        print('Yes')
        for j in an:
            print(j)
    else:
        print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from collections import deque
    import sys

    n,m =map(int,input().split())
    abl=[[] for i in range(n)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a-1].append(b)
        abl[b-1].append(a)

    an=[0]*(n-1)
    tg = deque([1])
    wwk =deque([])
    con =0

    while con<=m*2:
        for i in range(len(tg)):
            itg = tg.pop()
            wk =deque(abl[itg-1])
            for j in range(len(wk)):
                iwk=wk.pop()
                con += 1
                if an[iwk-2]==0 and iwk!=1:
                    an[iwk-2]=itg
                    wwk.append(iwk)
                if all(an):
                    print('Yes')
                    for j in an:
                        print(j)
                    sys.exit()
        tg=deque(wwk)
        wwk =deque([])

    print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from collections import deque
    import sys

    n,m =map(int,input().split())
    abl=[[] for i in range(n)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a-1].append(b)
        abl[b-1].append(a)

    an=[0]*(n-1)
    tg = deque([1])
    wwk =deque([])
    con =0

    while con<=m*2:
        while len(tg)!=0:
            itg = tg.pop()
            wk =deque(abl[itg-1])
            for j in range(len(wk)):
                iwk=wk.pop()
                con += 1
                if an[iwk-2]==0 and iwk!=1:
                    an[iwk-2]=itg
                    wwk.append(iwk)
                if all(an):
                    print('Yes')
                    for j in an:
                        print(j)
                    sys.exit()
        tg=deque(wwk)
        wwk =deque([])

    print('No')


main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

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

n,m =map(int,input().split())
abl=[[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    abl[a-1].append(b)
    abl[b-1].append(a)

an=[0]*(n-1)
tg = deque([1])
wwk =deque([])
con =0

while con<=m*2:
    while len(tg)!=0:
        itg = tg.pop()
        wk =deque(abl[itg-1])
        for j in range(len(wk)):
            iwk=wk.pop()
            con += 1
            if an[iwk-2]==0 and iwk!=1:
                an[iwk-2]=itg
                wwk.append(iwk)
            if all(an):
                print('Yes')
                for j in an:
                    print(j)
                sys.exit()
        
    tg=deque(wwk)
    wwk =deque([])

print('No')

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import deque
    from sys import stdin
    readline = stdin.readline

    n,m = map(int, readline().split())
    abl =[[]for i in range(n)]
    for i in range(m):
        a,b = map(int,readline().split())
        abl[a-1].append(b)
        abl[b-1].append(a)
    
    an=[0]*(n-1)
    i=1
    wk=deque([i])
    wwk=deque([])
    il=deque(abl[0])

    while len(wk)>0:
        i=wk.pop()
        il=deque(abl[i-1])
        lil=len(il)

        for k in range(lil):
            iwk=il.pop()
            if an[iwk-2]==0 and iwk>1:
                wwk.append(iwk)
                an[iwk-2]=i
                if all(an):
                    print('Yes')
                    for i in an:
                        print(i)
                    sys.exit()
        if len(wk)==0:
            wk=deque(wwk)
            wwk=deque([])
    print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import deque
    from sys import stdin
    readline = stdin.readline

    n,m = map(int, readline().split())
    abl =[[]for i in range(n)]
    for i in range(m):
        a,b = map(int,readline().split())
        abl[a-1].append(b)
        abl[b-1].append(a)
    
    an=[0]*(n-1)
    i=1
    wk=deque([i])
    wwk=deque([])
    il=deque(abl[0])

    while any(wk):
        i=wk.pop()
        il=deque(abl[i-1])
        lil=len(il)
        for k in range(lil):
            iwk=il.pop()
            if an[iwk-2]==0 and iwk>1:
                wwk.append(iwk)
                an[iwk-2]=i
                if all(an):
                    print('Yes')
                    for i in an:
                        print(i)
                    sys.exit()
        if not(any(wk)):
            wk=deque(wwk)
            wwk=deque([])
    print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import deque
    from sys import stdin
    readline = stdin.readline
    n,m = map(int, readline().split())
    abl =[[]for i in range(n)]
    for i in range(m):
        a,b = map(int,readline().split())
        abl[a-1].append(b)
        abl[b-1].append(a)

    an=[0]*(n-1)
    i=1
    wk=deque([i])
    wwk=deque([])
    il=deque(abl[0])

    while any(wk):
        i=wk.pop()
        il=deque(abl[i-1])
        for k in range(len(il)):
            iwk=il.pop()
            if an[iwk-2]==0 and iwk>1:
                wwk.append(iwk)
                an[iwk-2]=i
                if all(an):
                    print('Yes')
                    for i in an:
                        print(i)
                    sys.exit()
        if not(any(wk)):
            wk=deque(wwk)
            j=len(wk)
            wwk=deque([])
    print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import deque
    from sys import stdin
    readline = stdin.readline
    n,m = map(int, readline().split())
    abl =[[]for i in range(n)]
    for i in range(m):
        a,b = map(int,readline().split())
        abl[a-1].append(b)
        abl[b-1].append(a)

    an=[0]*(n-1)
    i=1
    wk=deque([i])
    wwk=deque([])
    il=deque(abl[0])

    while any(wk):
        i=wk.pop()
        il=deque(abl[i-1])
        for k in range(len(il)):
            iwk=il.pop()
            if an[iwk-2]==0 and iwk>1:
                wwk.append(iwk)
                an[iwk-2]=i
                if all(an):
                    print('Yes')
                    for i in an:
                        print(i)
                    sys.exit()
        if not(any(wk)):
            wk=deque(wwk)
            wwk=deque([])
    print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import deque

    n,m = map(int,input().split())
    abl =[[]for i in range(n)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a-1].append(b)
        abl[b-1].append(a)

    an=[0]*(n-1)
    i=1
    wk=deque([i])
    wwk=deque([])
    il=deque(abl[0])

    while any(wk):
        i=wk.pop()
        il=deque(abl[i-1])
        for k in range(len(il)):
            iwk=il.pop()
            if an[iwk-2]==0 and iwk>1:
                wwk.append(iwk)
                an[iwk-2]=i
                if all(an):
                    print('Yes')
                    for i in an:
                        print(i)
                    sys.exit()
        if not(any(wk)):
            wk=deque(wwk)
            wwk=deque([])
    print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import deque

    n,m = map(int,input().split())
    abl =[[]for i in range(n)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a-1].append(b)
        abl[b-1].append(a)

    an=[0]*(n-1)
    i=1
    wk=deque([i])
    wwk=deque([])
    il=deque(abl[0])

    while any(wk):
        i=wk.pop()
        il=deque(abl[i-1])
        while any(il):
            iwk=il.pop()
            if an[iwk-2]==0 and iwk>1:
                wwk.append(iwk)
                an[iwk-2]=i
                if all(an):
                    print('Yes')
                    for i in an:
                        print(i)
                    sys.exit()
        if not(any(wk)):
            wk=deque(wwk)
            wwk=deque([])
    print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import numpy as np
    import sys
    from collections import deque

    n,m = map(int,input().split())
    ab = [[int(i) for i in input().split()] for i in range(m)]
    abl=[[] for i in range(n)]
    for i in range(len(ab)):
        abl[ab[i][0]-1].append(ab[i][1])
        abl[ab[i][1]-1].append(ab[i][0])

    an=[0]*(n-1)
    i=1
    wk=deque([i])
    wwk=deque([])
    il=deque(abl[0])

    while any(wk):
        i=wk.pop()
        il=deque(abl[i-1])
        while any(il):
            iwk=il.pop()
            if an[iwk-2]==0 and iwk>1:
                wwk.append(iwk)
                an[iwk-2]=i
                if all(an):
                    print('Yes')
                    for i in an:
                        print(i)
                    sys.exit()
        if not(any(wk)):
            wk=deque(wwk)
            wwk=deque([])
    print('No')

main()

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
from collections import deque

n,m = map(int,input().split())
ab = [[int(i) for i in input().split()] for i in range(m)]
abl=[[] for i in range(n)]
for i in range(len(ab)):
    abl[ab[i][0]-1].append(ab[i][1])
    abl[ab[i][1]-1].append(ab[i][0])

an=[0]*(n-1)
i=1
wk=deque([i])
wwk=deque([])
il=deque(abl[0])

while any(wk):
    i=wk.pop()
    il=deque(abl[i-1])
    while any(il):
        iwk=il.pop()
        if an[iwk-2]==0 and iwk>1:
            wwk.append(iwk)
            an[iwk-2]=i
            if all(an):
                print('Yes')
                for i in an:
                    print(i)
                sys.exit()
    if not(any(wk)):
        wk=deque(wwk)
        wwk=deque([])
print('No')

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
from collections import deque

n,m = map(int,input().split())
ab = [[int(i) for i in input().split()] for i in range(m)]
abl=[[] for i in range(n)]
for i in range(len(ab)):
    abl[ab[i][0]-1].append(ab[i][1])
    abl[ab[i][1]-1].append(ab[i][0])

an=[0]*(n-1)
i=1
wk=deque([i])
wwk=deque([])
il=deque(abl[0])

while any(wk):
    i=wk.pop()
    il=abl[i-1]
    while any(il):
        iwk=il.pop()
        if an[iwk-2]==0 and iwk>1:
            wwk.append(iwk)
            an[iwk-2]=i
            if all(an):
                print('Yes')
                for i in an:
                    print(i)
                sys.exit()
    if not(any(wk)):
        wk=deque(wwk)
        wwk=deque([])
print('No')

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys

n,m = map(int,input().split())
ab = [[int(i) for i in input().split()] for i in range(m)]

an=[0]*(n-1)
wk=[0]*n
awk=np.array(wk)
aab=np.array(ab)
tg =[1]
wtg=[]

while not(all(an)):# or len(aab)<=0:
    if len(aab)<=0:
        break
    for i in tg:
        awk=aab[np.any(aab==i,axis=1)]
        for j in range(len(awk)):
            if awk[j][0]==i:
                if an[awk[j][1]-2]==0:
                    an[awk[j][1]-2]=i
                    wtg.append(awk[j][1])
            else:
                if an[awk[j][0]-2]==0:
                    an[awk[j][0]-2]=i
                    wtg.append(awk[j][0])
            aab=aab[~np.any(aab==tg,axis=1)]

    tg=list(wtg)
    wtg=[]
if all(an):
    print('Yes')
    for i in an:
        print(i)
else:
    print('No')

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys

n,m = map(int,input().split())
ab = [[int(i) for i in input().split()] for i in range(m)]

an=[0]*(n-1)
wk=[0]*n
awk=np.array(wk)
aab=np.array(ab)
tg =[1]
wtg=[]

while not(all(an)):# or len(aab)<=0:
    if len(aab)<=0:
        break
    for i in tg:
        awk=aab[np.any(aab==i,axis=1)]
        for j in range(len(awk)):
            if awk[j][0]==i:
                if an[awk[j][1]-2]==0:
                    an[awk[j][1]-2]=i
                    wtg.append(awk[j][1])
            else:
                if an[awk[j][0]-2]==0:
                    an[awk[j][0]-2]=i
                    wtg.append(awk[j][0])
            aab=aab[~np.any(aab==tg,axis=1)]

    tg=list(wtg)
    wtg=[]
if all(an):
    print('Yes')
    for i in an:
        print(i)
else:
    print('No')

Fixed submission:
def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()