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 1837. Isenbaev's Number

Runtime Error (Python)
Posted by JuliM 9 Aug 2016 16:37
Test 3 is RTE
What can I optimise?

n=int(input())
dic={}
for i in range(n):
    team=input().split()
    for x in team:
        if x in dic:
            dic[x].extend((y for y in team if y!=x and y not in dic[x]))
        else:
            dic[x]=[y for y in team if y!=x]
names=sorted(dic.keys())
s='Isenbaev'
level = { s: 0 }
k = 1
frontier = [s]
while frontier:
    next = []
    for u in frontier:
        for v in dic[u]:
            if v not in level:
                level[v] = k
                next.append(v)
    frontier = next
    k += 1
print('\n'.join((x+' '+str(level.get(x, 'undefined')) for x in names)))

Edited by author 09.08.2016 16:37