ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1137. Автобусные маршруты

why crash test 5???
Послано scythe 22 май 2012 02:18
Re: why crash test 5???
Послано scythe 22 май 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???
Послано AutumnSky 14 сен 2012 01:22
I have the same problem. In what direction i must dig? (C# is my language)
Re: why crash test 5???
Послано AutumnSky 24 сен 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???
Послано Douglas 26 сен 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 писал(a) 24 сентября 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???
Послано fblassioli 29 сен 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