title: Algoriithm to store dist(node, start) for all nodes in an undirected graph
body: <p>The goal is to create an array called siz that stores the length of all the paths from a starting node. In the  ideal case, I would call f(start) and expect siz[v] to get filled up for all vertices v in the graph.</p>
  
  <p>This the algorithm that I am using.</p>
  
  <pre><code>def f (node):
      vis[node] = 1
      for elem in adj[node]:
          if vis[elem]==0:
              for i in siz[node]:
                      siz[elem].append(i + w[(node,elem)])
              f(elem)
  </code></pre>
  
  <p>Variable descriptions :</p>
  
  <ol>
  <li>adj[cur_nod] contains all the neighbors of the node cur_nod</li>
  <li>siz[cur_nod] (which is a list not an int data type) contains all the distances from node 1 to node 
  cur_nod</li>
  <li>w(x,y) denotes the weight of the edge joining the nodes x and y</li>
  <li>vis[nod] tracks if a node is visited. 0 for not, 1 for visited.</li>
  </ol>
  
  <p>The recursion doesn't seem correct and I don't know when to actually mark a node as visited. Also, since there are cycles, I do not want distances to include cycles. For instance, A -> B -> C -> A -> D should not be a case at all. It should just be A -> D or all other ways there is a path from A to D without going through a cycle.</p>
  
  <p>To give an example of how this algorithm doesn't work as intended :</p>
  
  <p>If I enter the nodes and the edge weights as w(1,2)=1, w(2,3)=2, w(2,4)=7 and w(3,4)=1. </p>
  
  <p>Then siz = [[-1], [0], [1], [3], [4]]. (Do note that I have set siz[1]=0 and siz[0]=-1 initially since my start node is 1 and the array is 0-indexed but I need it as 1-indexed) while the ideal siz should have been [[-1], [0], [1], [3,9], [4,8]]</p>