title: Finding out if it is possible to balance out debts between people using a graph
body: <p>Say a bunch of friends went on a trip. Something went wrong, and when they got back, some were not friends anymore. Now we need to find a way to split the cost of the trip. Some people are owed money (because they paid too much) and some are owing (paid too little).</p>
  
  <p>Say we have two lists, debts and relationship. The debts list contains a list of integers. Each integer is a person. A positive integer means they owe that much money, negative means that are owed that much. Relationships is a list of tuples that shows if two people are friends. For instance (0, 3) would mean that debts[0] and debts[3] are friends. I'm trying to find a way to see if everyone can get even by transferring money between people. </p>
  
  <p>An example: </p>
  
  <pre><code>debts = [5, -5, 10]
  relationship = [(0, 1), (1, 2)]
  </code></pre>
  
  <p>The way I was thinking was making a graph to construct the relationships between each individual. Using DFS, I would start with the first person, clear their debt (i.e make it 0) and passing that money on to the next person. Eventually I would have gone through everyone and if at the end the last person does not have a value of 0, it is not possible to get even.</p>
  
  <p>Am I on the correct path? I believe this would take O(|V|+|E|)</p>