Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
l.append(0)
while True:
  for i in path[l[0]]:
    if not i in l:
      l.appendleft(i)
      break
  else:break
while True:
  for i in path[l[-1]]:
    if not i in l:
      l.append(i)
      break
  else:break
print(len(l))
l=list(map(lambda x:x+1,l))
print(*l)

Fixed submission:
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
s=set()
l.append(0)
s.add(0)
while True:
  for i in path[l[0]]:
    if not i in s:
      l.appendleft(i)
      s.add(i)
      break
  else:break
while True:
  for i in path[l[-1]]:
    if not i in s:
      l.append(i)
      s.add(i)
      break
  else:break
print(len(l))
l=list(map(lambda x:x+1,l))
print(*l)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
l.append(0)
cnt=[False]*n
while True:
  flag=True
  if not cnt[l[0]]:
    for i in path[l[0]]:
      if not i in l:
        l.appendleft(i)
        flag=False
        break
    else:cnt[l[0]]=True
  if not cnt[l[-1]]:
    for i in path[l[-1]]:
      if not i in l:
        l.append(i)
        flag=False
        break
    else:cnt[l[-1]]=True
  if flag or len(l)==n:
    break
print(len(l))
l=list(map(lambda x:x+1,l))
print(*l)

Fixed submission:
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
s=set()
l.append(0)
s.add(0)
while True:
  for i in path[l[0]]:
    if not i in s:
      l.appendleft(i)
      s.add(i)
      break
  else:break
while True:
  for i in path[l[-1]]:
    if not i in s:
      l.append(i)
      s.add(i)
      break
  else:break
print(len(l))
l=list(map(lambda x:x+1,l))
print(*l)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
l.append(1)
while True:
  flag=True
  for i in path[l[0]]:
    if not i in l:
      l.appendleft(i)
      flag=False
      break
  for i in path[l[-1]]:
    if not i in l:
      l.append(i)
      flag=False
      break
  if flag or len(l)==n:
    break
print(len(l))
for i in range(len(l)):
  l[i]+=1
print(*l)

Fixed submission:
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
s=set()
l.append(0)
s.add(0)
while True:
  for i in path[l[0]]:
    if not i in s:
      l.appendleft(i)
      s.add(i)
      break
  else:break
while True:
  for i in path[l[-1]]:
    if not i in s:
      l.append(i)
      s.add(i)
      break
  else:break
print(len(l))
l=list(map(lambda x:x+1,l))
print(*l)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
l.append(0)
while True:
  flag=True
  for i in path[l[0]]:
    if not i in l:
      l.appendleft(i)
      flag=False
      break
  for i in path[l[-1]]:
    if not i in l:
      l.append(i)
      flag=False
      break
  if flag or len(l)==n:
    break
print(len(l))
for i in range(len(l)):
  l[i]+=1
print(*l)

Fixed submission:
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
s=set()
l.append(0)
s.add(0)
while True:
  for i in path[l[0]]:
    if not i in s:
      l.appendleft(i)
      s.add(i)
      break
  else:break
while True:
  for i in path[l[-1]]:
    if not i in s:
      l.append(i)
      s.add(i)
      break
  else:break
print(len(l))
l=list(map(lambda x:x+1,l))
print(*l)

Buggy python submission (verdict: Time Limit Exceeded):

from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
l.append(0)
while True:
  flag=True
  for i in path[l[0]]:
    if not i in l:
      l.appendleft(i)
      flag=False
      break
  for i in path[l[-1]]:
    if not i in l:
      l.append(i)
      flag=False
      break
  if flag or len(l)==n:
    break
print(len(l))
for i in range(len(l)):
  l[i]+=1
print(*l)

Fixed submission:
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
s=set()
l.append(0)
s.add(0)
while True:
  for i in path[l[0]]:
    if not i in s:
      l.appendleft(i)
      s.add(i)
      break
  else:break
while True:
  for i in path[l[-1]]:
    if not i in s:
      l.append(i)
      s.add(i)
      break
  else:break
print(len(l))
l=list(map(lambda x:x+1,l))
print(*l)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
l.append(0)
while True:
  flag=True
  for i in path[l[0]]:
    if not i in l:
      l.appendleft(i)
      flag=False
      break
  for i in path[l[-1]]:
    if not i in l:
      l.append(i)
      flag=False
      break
  if flag:
    break
print(len(l))
for i in range(len(l)):
  l[i]+=1
print(*l)

Fixed submission:
from collections import deque
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
l=deque()
s=set()
l.append(0)
s.add(0)
while True:
  for i in path[l[0]]:
    if not i in s:
      l.appendleft(i)
      s.add(i)
      break
  else:break
while True:
  for i in path[l[-1]]:
    if not i in s:
      l.append(i)
      s.add(i)
      break
  else:break
print(len(l))
l=list(map(lambda x:x+1,l))
print(*l)