hello
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 :)

Edited 1 Year Ago by Baalla: i forget to mention something

Attachments adj.PNG 6.12 KB

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:

degree.push_back(adj[i].size());

This question has already been answered. Start a new discussion instead.