Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#Python - (削除) 239 (削除ここまで)(削除) 237 (削除ここまで) 236

Python - (削除) 239 (削除ここまで)(削除) 237 (削除ここまで) 236

import sys
global d
d={}
for i in sys.stdin:
 a,b=[int(c) for c in i.split(' ')]
 try: d[b]+=[a]
 except: d[b]=[a]
def f(x,h):
 j=h+[x]
 if x==1:
 print ''.join([str(a)+" " for a in j[::-1]])
 exit()
 for i in d[x]:
 f(i,j)
f(100,[])

unfortunately, this tail-recursive solution is vulnerable to loops in the "story"...

Usage: cat ./test0 | ./sol.py Output for test case 1:

1 10 13 15 100

Output for test case 2:

1 15 2 12 80 100

#Python - (削除) 239 (削除ここまで)(削除) 237 (削除ここまで) 236

import sys
global d
d={}
for i in sys.stdin:
 a,b=[int(c) for c in i.split(' ')]
 try: d[b]+=[a]
 except: d[b]=[a]
def f(x,h):
 j=h+[x]
 if x==1:
 print ''.join([str(a)+" " for a in j[::-1]])
 exit()
 for i in d[x]:
 f(i,j)
f(100,[])

unfortunately, this tail-recursive solution is vulnerable to loops in the "story"...

Usage: cat ./test0 | ./sol.py Output for test case 1:

1 10 13 15 100

Output for test case 2:

1 15 2 12 80 100

Python - (削除) 239 (削除ここまで)(削除) 237 (削除ここまで) 236

import sys
global d
d={}
for i in sys.stdin:
 a,b=[int(c) for c in i.split(' ')]
 try: d[b]+=[a]
 except: d[b]=[a]
def f(x,h):
 j=h+[x]
 if x==1:
 print ''.join([str(a)+" " for a in j[::-1]])
 exit()
 for i in d[x]:
 f(i,j)
f(100,[])

unfortunately, this tail-recursive solution is vulnerable to loops in the "story"...

Usage: cat ./test0 | ./sol.py Output for test case 1:

1 10 13 15 100

Output for test case 2:

1 15 2 12 80 100

#Python - (削除) 239 (削除ここまで) 237(削除) 237 (削除ここまで) 236

import sys
global d
d={}
for i in sys.stdin:
 a,b=[int(c) for c in i.split(' ')]
 try: d[b]+=[a]
 except: d[b]=[a]
def f(x,h):
 j=h+[x]
 if x==1:
 print ''.join([str(a)+" " for a in j[::-1]])
 exit()
 for i in d[x]:
 f(i,j)
f(100,[])

unfortunately, this tail-recursive solution is vulnerable to loops in the "story"...

Usage: cat ./test0 | ./sol.py Output for test case 1:

1 10 13 15 100

Output for test case 2:

1 15 2 12 80 100

#Python - (削除) 239 (削除ここまで) 237

import sys
global d
d={}
for i in sys.stdin:
 a,b=[int(c) for c in i.split(' ')]
 try: d[b]+=[a]
 except: d[b]=[a]
def f(x,h):
 j=h+[x]
 if x==1:
 print ''.join([str(a)+" " for a in j[::-1]])
 exit()
 for i in d[x]:
 f(i,j)
f(100,[])

unfortunately, this tail-recursive solution is vulnerable to loops in the "story"...

Usage: cat ./test0 | ./sol.py Output for test case 1:

1 10 13 15 100

Output for test case 2:

1 15 2 12 80 100

#Python - (削除) 239 (削除ここまで) (削除) 237 (削除ここまで) 236

import sys
global d
d={}
for i in sys.stdin:
 a,b=[int(c) for c in i.split(' ')]
 try: d[b]+=[a]
 except: d[b]=[a]
def f(x,h):
 j=h+[x]
 if x==1:
 print ''.join([str(a)+" " for a in j[::-1]])
 exit()
 for i in d[x]:
 f(i,j)
f(100,[])

unfortunately, this tail-recursive solution is vulnerable to loops in the "story"...

Usage: cat ./test0 | ./sol.py Output for test case 1:

1 10 13 15 100

Output for test case 2:

1 15 2 12 80 100
added 12 characters in body
Source Link
arrdem
  • 846
  • 5
  • 15

#Python - 239(削除) 239 (削除ここまで) 237

import sys as s
global d
d={}
for i in ssys.stdin:
 a,b=[int(c) for c in i.split(' ')]
 try: d[b]+=[a]
 except: d[b]=[a]
def f(x,h):
 j=h+[x]
 if x==1:
 print ''.join([str(a)+" " for a in j[::-1]])
 exit()
 for i in d[x]:
 f(i,j)
f(100,[])

unfortunately, this tail-recursive solution is vulnerable to loops in the "story"...

Usage: cat ./test0 | ./sol.py Output for test case 1:

1 10 13 15 100

Output for test case 2:

1 15 2 12 80 100

#Python - 239

import sys as s
global d
d={}
for i in s.stdin:
 a,b=[int(c) for c in i.split(' ')]
 try: d[b]+=[a]
 except: d[b]=[a]
def f(x,h):
 j=h+[x]
 if x==1:
 print ''.join([str(a)+" " for a in j[::-1]])
 exit()
 for i in d[x]:
 f(i,j)
f(100,[])

unfortunately, this tail-recursive solution is vulnerable to loops in the "story"...

Usage: cat ./test0 | ./sol.py Output for test case 1:

1 10 13 15 100

Output for test case 2:

1 15 2 12 80 100

#Python - (削除) 239 (削除ここまで) 237

import sys
global d
d={}
for i in sys.stdin:
 a,b=[int(c) for c in i.split(' ')]
 try: d[b]+=[a]
 except: d[b]=[a]
def f(x,h):
 j=h+[x]
 if x==1:
 print ''.join([str(a)+" " for a in j[::-1]])
 exit()
 for i in d[x]:
 f(i,j)
f(100,[])

unfortunately, this tail-recursive solution is vulnerable to loops in the "story"...

Usage: cat ./test0 | ./sol.py Output for test case 1:

1 10 13 15 100

Output for test case 2:

1 15 2 12 80 100
Source Link
arrdem
  • 846
  • 5
  • 15
Loading

AltStyle によって変換されたページ (->オリジナル) /