Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
t=[1]*(n+1)
p=0
for i in range(m):
    a,b=map(int,input().split())
    if i==0:
        k=[a,b]
        t[a],t[b]=0,0
    else:
        if a==k[0] and t[b]==1:
            k=[b]+k
            t[b]=0
        elif b==k[0] and t[a]==1:
            k=[a]+k
            t[a]=0
        elif a==k[-1] and t[b]==1:
            k.append(b)
            t[b]=0
        elif b==k[-1] and t[a]==1:
            k.append(a)
            t[a]=0
        else:
            s[a].append(b)
            s[b].append(a)
p=len(k)
while p!=n:
    c=0
    for i in s[k[-1]]:
        if t[i]:
            t[i]=0
            k.append(i)
            p+=1
            break
    else:
        c+=1
    for i in s[k[0]]:
        if t[i]:
            t[i]=0
            k=[i]+k
            p+=1
            break
    else:
        c+=1
        if c==2:
            break
print(p)
print(*k)

Fixed submission:
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
t=[1]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
a,b=[],[]
p=1
t[1]=0
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            a.append(i)
            break
    else:
        break
p=1
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            b.append(i)
            break
    else:
        break
print(1+len(a)+len(b))
t=a[::-1]+[1]+b
print(*t)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
t=[1]*(n+1)
p=0
for i in range(m):
    a,b=map(int,input().split())
    if i==0:
        k=[a,b]
        t[a],t[b]=0,0
    else:
        if a==k[0] and t[b]==1:
            k=[b]+k
        elif b==k[0] and t[a]==1:
            k=[a]+k
        elif a==k[1] and t[b]==1:
            k.append(b)
        elif b==k[1] and t[a]==1:
            k.append(a)
        else:
            s[a].append(b)
            s[b].append(a)
p=len(k)
while p!=n:
    for i in s[k[-1]]:
        if t[i]:
            t[i]=0
            k.append(i)
            p+=1
            break
    else:
        c=1
    for i in s[k[0]]:
        if t[i]:
            t[i]=0
            k=[i]+k
            p+=1
            break
    else:
        c+=1
        if c==2:
            break
print(p)
print(*k)

Fixed submission:
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
t=[1]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
a,b=[],[]
p=1
t[1]=0
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            a.append(i)
            break
    else:
        break
p=1
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            b.append(i)
            break
    else:
        break
print(1+len(a)+len(b))
t=a[::-1]+[1]+b
print(*t)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
t=[1]*(n+1)
p=2
k=[a,b]
t[a],t[b]=0,0
while p!=n:
    c=0
    for i in s[k[-1]]:
        if t[i]:
            t[i]=0
            k.append(i)
            p+=1
            break
    else:
        c+=1
    for i in s[k[0]]:
        if t[i]:
            t[i]=0
            k=[i]+k
            p+=1
            break
    else:
        c+=1
        if c==2:
            break
print(p)
print(*k)

Fixed submission:
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
t=[1]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
a,b=[],[]
p=1
t[1]=0
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            a.append(i)
            break
    else:
        break
p=1
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            b.append(i)
            break
    else:
        break
print(1+len(a)+len(b))
t=a[::-1]+[1]+b
print(*t)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
t=[1]*(n+1)
p=2
k=[a,b]
t[a],t[b]=0,0
while p!=n:
    c=0
    for i in s[k[-1]]:
        if t[i]:
            t[i]=0
            k.append(i)
            p+=1
            break
    else:
        c+=1
    for i in s[k[0]]:
        if t[i]:
            t[i]=0
            k=[i]+k
            p+=1
            break
    else:
        c+=1
        if c==2:
            break
print(p)
print(*k)

Fixed submission:
n,m=map(int,input().split())
s=[[]for i in range(n+1)]
t=[1]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
a,b=[],[]
p=1
t[1]=0
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            a.append(i)
            break
    else:
        break
p=1
while 1:
    for i in s[p]:
        if t[i]:
            t[i]=0
            p=i
            b.append(i)
            break
    else:
        break
print(1+len(a)+len(b))
t=a[::-1]+[1]+b
print(*t)