Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Owing = false
- Owed = false
- pathTotal = 0
- DFS(owing, friendship):
- for student in owing:
- student.color = white
- student.pred = null
- student.area = null
- for student in friendship:
- if student.color == white:
- DFS_VISIT(student, owing, friendship)
- DFS_VISIT(student, owing, friendship)
- // Get all students current student is friends with
- for x in friendship:
- if x pair student:
- student.adj = student.adj + x
- // Check if adjacent members have not been visited
- for i in student.adj:
- if i.color != white:
- if owing[i] > 0:
- Owing = true
- else if owing[i] < 0:
- Owed = true
- // If it hasn't been visited
- if student.color == white:
- Owing = false
- Owed = false
- if student.pred == null:
- if owing[student] != 0:
- return "Failure"
- else:
- pathTotal = pathTotal + owing[student]
- // Calculated debt
- student.color = grey
- // Recursively go through the rest of the list
- for t in student.adj:
- if t.colot == white:
- t.pred = student
- DFS_VISIT(t, owing, friendship)
- // All neighbors visited
- student.color = black;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement