Skip to content

Instantly share code, notes, and snippets.

@laat
Created August 27, 2010 15:35
Show Gist options
  • Save laat/553595 to your computer and use it in GitHub Desktop.
Save laat/553595 to your computer and use it in GitHub Desktop.
def main():
from sys import stdin
rl=stdin.readline
rl()
rl()
root = rl().rstrip()
ratatosk = rl().rstrip()
parent = {}
count = 0
for node in stdin:
node = node.split()
t=node.pop(0)
for n in node:
parent[n]=t
while parent.has_key(ratatosk):
ratatosk=parent[ratatosk]
count+=1
if ratatosk == root:
print count
return
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment