title: Declaring a vector<vector<pair<int, int>> with a specific size and inserting elements?
body: <p>I want to represent a graph data structure and I am using vector of vector of pairs in c++ stl. Example:</p>
  
  <pre><code>vector&lt;vector&lt;pair&lt;int, int&gt;&gt;&gt; G;
  </code></pre>
  
  <p>Now I can do, <code>G[u].push_back(make_pair(v, w));</code> </p>
  
  <p>The problem: I need to specify this data structure a size. If I don't I get a segmentation fault when I try to push elements to this data structure. If I do give a size like:</p>
  
  <pre><code>vector&lt; vector&lt;ii&gt; &gt; adj(10, std::vector&lt;ii&gt;(10));
  </code></pre>
  
  <p>The problem now is the first 10 pairs of vector are initialized to zero. If I push back an element now, it gets pushed to the 11th position. The first 10 being 0s. I don't want to do this. I want to insert elements in the order I need. A snippet to give you an idea about what I am trying to do:</p>
  
  <pre><code> for(int i=0;i&lt;E-1;i++)
          {
              cin &gt;&gt; p &gt;&gt; q &gt;&gt; l;
              adj[p].push_back(ii(q, l));
              adj[q].push_back(ii(p, l));
          } 
  </code></pre>
  
  <p>The output for the above would be 10 zeros followed by the values pushed. Any way to get around this?</p>