0
#include <bits/stdc++.h>
using namespace std;
vector< vector<int> >Adj;
int main()
{
    int n;
    cin>>n;
    Adj.assign(n);
}

This code doesn't work for assigning size to the vector.

Pushacker
  • 3
  • 2
  • 2
    The size of a vector is set with the [resize](https://en.cppreference.com/w/cpp/container/vector/resize) method. – mkaes Apr 03 '21 at 11:32
  • Why did you assume `assign` would change the size? It can, just not this way. Guessing what a function might do makes programming quite hard, instead you should refer to [some reference](https://en.cppreference.com/w/cpp/container/vector/assign). Other good reading: [Why should I not #include ?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h), [Why is “using namespace std;” considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). – Lukas-T Apr 03 '21 at 11:51

1 Answers1

0
  1. Use resize method 'Adj.resize(n)'. The function alters the container’s content in actual by inserting or deleting the elements from it.
  2. If the given value of n is less than the size at present then extra elements are demolished.
  3. If n is more than current size of container then upcoming elements are appended at the end of the vector
Rana Vivek
  • 126
  • 2