I have the same problem, I am a python programer here is my code:

import sys

sys.setrecursionlimit(10**5)

def find_tour(G):

"""

Where G is an undirected graph

"""

tour=[]

visited_edges=set()

def recurse(u):

for v in G[u]:

if (u,v) in visited_edges:continue

visited_edges.add((u,v))

recurse(v)

tour.append(u)

recurse(G.keys()[0])

tour.reverse()

return tour

from collections import defaultdict

def main():

G=defaultdict(list)

n=input()

for t in range(n):

l=map(int,raw_input().strip().split())

for i in range(1,l[0]+1):

G[l[i]].append(l[i+1])

r=find_tour(G)

if len(r) and r[0]==r[-1]:

s=" ".join(map(str,r))

s=str(len(r)-1)+" "+s

print s

else:print 0

main()

The error is in the reading phase, but when I change the read part to:

try:

tokenizer=chain.from_iterable(line.strip().split() for line in stdinf)

n=int(tokenizer.next())

for i in range(n):

m=int(tokenizer.next())

u,v=-1,int(tokenizer.next())

for j in range(m):

u=v

v=int(tokenizer.next())

G[u].append(v)

# print G

except:

pass

I got an error in the 1st test case even when I dont have the same problem in my laptop.

Thanks for any help that you can give me.

OK, I did it. You need to read input until end (C++ style!). In C# you can use structure like that:

while(Console.In.Peek() != -1)

{

//read input

}

Good luck :)