title: Print weak component of a graph vector of vectors
body: <p>I'm programing a C++ program which has to work with graphs. And I have a litle problem with one of the methods. So, my structure looks like </p>
  
  <pre><code>struct graph {  
      std::vector &lt;std::vector&lt;int&gt;&gt; gr;
  };
  </code></pre>
  
  <p>And I have a method which has to return vertices inside the weak component originating at vertex and it can only be called with existing vertex.</p>
  
  <p>So here it is:</p>
  
  <pre><code>std::vector&lt;int&gt; weak_component(const graph&amp; g, int vertex) {
      std::vector&lt;int&gt; ret;   
      if (vertex &gt;= 0 &amp;&amp; vertex &lt; g.gr.size()) {
          for (std::vector&lt;std::vector&lt;int&gt;&gt;::size_type i = 0; 
               i &lt; g.gr[vertex].size(); i++) {
              for (std::vector&lt;int&gt;::size_type j = 0; j &lt; g.gr[i].size(); j++) {
                  std::fill(ret.begin(), ret.begin(), g.gr[i][j]);
                  std::cout &lt;&lt; vertex; 
              }
          }   
      }
      return ret; 
  }
  </code></pre>
  
  <p>I'm trying to fill another vector and return it. 
  So for example: if I would fill a test graph with data </p>
  
  <pre><code> 0, 1
   1, 2
   1, 3
  </code></pre>
  
  <p>And call method <code>weak_component(g, 0)</code> the return value shoul be <code>0, 1, 2, 3</code>.
  What am I doing wrong in my method? 
  Thank you for help.</p>