ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1137. Bus Routes

why crash test 5???
Posted by scythe 22 May 2012 02:18
Re: why crash test 5???
Posted by scythe 22 May 2012 02:44
Is something wrong with the input file format, is not as in the specification ( i lost 4 hours because of this ).

To be sure read it with Scanner ( if you use java ).


Edited by author 22.05.2012 02:47

Edited by author 22.05.2012 02:47
Re: why crash test 5???
Posted by AutumnSky 14 Sep 2012 01:22
I have the same problem. In what direction i must dig? (C# is my language)
Re: why crash test 5???
Posted by AutumnSky 24 Sep 2012 23:09
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 :)
Re: why crash test 5???
Posted by Douglas 26 Sep 2014 08:58
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.




AutumnSky wrote 24 September 2012 23:09
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 :)
Re: why crash test 5???
Posted by fblassioli 29 Sep 2015 06:14
Yes, got problem with test #5 input.
Got AC after reading it the following way (python 2.7):

all_input = iter(sys.stdin.read().strip().replace('\n', ' ').split(' '))
n = int(all_input.next())
for _ in xrange(n):
    m = int(all_input.next())
    u = all_input.next()
    for i in xrange(m):
        v = all_input.next()
    ...

        u = v

Edited by author 29.09.2015 06:14

Edited by author 29.09.2015 06:14