Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. Owing = false
  2. Owed = false
  3. pathTotal = 0
  4.  
  5. DFS(owing, friendship):
  6. for student in owing:
  7. student.color = white
  8. student.pred = null
  9. student.area = null
  10.  
  11. for student in friendship:
  12. if student.color == white:
  13. DFS_VISIT(student, owing, friendship)
  14.  
  15. DFS_VISIT(student, owing, friendship)
  16. // Get all students current student is friends with
  17. for x in friendship:
  18. if x pair student:
  19. student.adj = student.adj + x
  20.  
  21. // Check if adjacent members have not been visited
  22. for i in student.adj:
  23. if i.color != white:
  24. if owing[i] > 0:
  25. Owing = true
  26. else if owing[i] < 0:
  27. Owed = true
  28.  
  29. // If it hasn't been visited
  30. if student.color == white:
  31. Owing = false
  32. Owed = false
  33.  
  34. if student.pred == null:
  35. if owing[student] != 0:
  36. return "Failure"
  37.  
  38. else:
  39. pathTotal = pathTotal + owing[student]
  40.  
  41. // Calculated debt
  42. student.color = grey
  43.  
  44. // Recursively go through the rest of the list
  45. for t in student.adj:
  46. if t.colot == white:
  47. t.pred = student
  48. DFS_VISIT(t, owing, friendship)
  49.  
  50. // All neighbors visited
  51. student.color = black;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement