my problem this time is i have an multidimensional vector and the example of adj vector is showen in the attached picture
and i wanna know the size of each one i mean in i=0 the size is 2
i declare a new vector degree to put in it the size as shown in the code:

vector<int> degree;
for(int i=0; i <n ; i++ )
        degree[i] = adj[i].size();
   cout << "the degree are: \n";
    for (int i = 0; i < n; ++i) {
        cout << degree.at(i) << ", ";

but when i compile it i get this error

any helpful ideas? i'll really appreciate the help thanks in advance :)

When you're using a vector that doesn't have any elements in it, you can't use the index operator([]) you have to add what you want to put into the vector:


thank you sir that worked