fork download
  1. def dfs_rec(adjLists, visited, v):
  2. visited[v] = True
  3. print(v)
  4. for w in adjLists[v]:
  5. if(not visited[w]):
  6. dfs_rec(adjLists, visited, w)
  7.  
  8.  
  9. # Usually dfs_rec() would be sufficient. However, if we don't want to pass
  10. # a boolean array to our function, we can use another function dfs().
  11. # We only have to pass the adjacency list and the source node to dfs(),
  12. #as opposed to dfs_rec(), where we have to pass the boolean array additionally.
  13. def dfs(adjLists, s):
  14. visited = []
  15. n = len(adjLists)
  16. for i in range(n):
  17. visited.append(False)
  18. dfs_rec(adjLists, visited, s)
  19.  
  20. # ------------------------------------------------------------------
  21. x=input()
  22. a=[]
  23. p=[]
  24. a = [int(i) for i in raw_input().split()]
  25. p = [int(i) for i in raw_input().split()]
  26. z=max(a)
  27. r=min(p)
  28. for l in range(n):
  29. if p[l]==r:
  30. break
  31. adjLists=[[0 for i in range(x-1)]for i in range(z)]
  32. for i in range(x):
  33. k=0
  34. for j in range(x):
  35. if p[i]==p[j]:
  36. adjLists[a(p[j]-1)][k]=a[j]
  37. k=k+1
  38.  
  39.  
  40. # test our implementation
  41. dfs(adjLists, a[l])# your code goes here# your code goes here
Runtime error #stdin #stdout #stderr 0s 23352KB
stdin
4
5 10 6 12
2 -1 4 2
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 28, in <module>
NameError: name 'n' is not defined