fork download
  1. def ara_ara():
  2. N={}
  3. while 1:
  4. src=input()
  5. temp=src.split()
  6. if len(temp)==1:
  7. start=src
  8. fin=input()
  9. break
  10. if N.get(temp[0]) is None:
  11. N[temp[0]]=eval('["'+str(temp[1])+'"]')
  12. else:
  13. N[temp[0]] = eval(str(N.get(temp[0]))[0:-1]+',"'+temp[1]+'"]')
  14.  
  15. if N.get(temp[1]) is None:
  16. N[temp[1]]=eval('["'+str(temp[0])+'"]')
  17. else:
  18. N[temp[1]] = eval(str(N.get(temp[1]))[0:-1]+',"'+temp[0]+'"]')
  19. path=[]
  20. q=[start]
  21. while q:
  22. v=q.pop()
  23. if v not in path:
  24. path = path +[v]
  25. q=q+N[v]
  26. if fin in path: return 'YES'
  27. else: return 'NO'
  28.  
  29.  
  30. if __name__ == '__main__':
  31. print(ara_ara())
Runtime error #stdin #stdout #stderr 0.14s 23440KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 31, in <module>
  File "./prog.py", line 4, in ara_ara
EOFError: EOF when reading a line