title: How to find union of n vector?
body: <p>I have a 2-D vector of hyperedges as well as an adjacency list. I have to find the union of <code>hyperEdges[i].size()</code> vectors, but I can only find the union of just two vectors. What improvement can I make to my code below to do this?
  I want to store the union into newly declared 2-D vector <code>connectedEdges</code> </p>
  
  <pre><code>void find_union()
  {
      connectedEdges.resize(nEdges+1);
      for(int i = 1; i &lt;= nEdges; i++)
      {
          vector&lt;int&gt;::iterator it;
          connectedEdges[i].resize(nEdges+1);
  
          for(int j = 1; j &lt; hyperEdges[i].size()-1; j++)
          {
              int p = hyperEdges[i][j-1];
              int q= hyperEdges[i][j];
              it = set_union(adjL[p].begin(), adjL[p].end(),adjL[q].begin(),adjL[q].end(), connectedEdges[i].begin());
          connectedEdges[i].resize(it-connectedEdges[i].begin());
          }
      }    
  }
  </code></pre>
  
  <p><strong>Example :</strong> 
  <code>{1,2,4,6,8}</code></p>
  
  <p><code>{1,2,3,5,6}</code></p>
  
  <p><code>{1,4,7,13,15}</code></p>
  
  <p>Union of these three sets should be <code>{1,2,3,4,5,6,7,8,13,15}</code>
  But my program returns <code>{1,2,3,4,5,6,8}</code></p>