J. Doe
J. Doe

Reputation: 1341

About using range based for loop over a vector of vectors

I am working on some graph problem. I have:

vector<vector<int>> e

that I populate as:

for(vector<int> edge: edges) {
    e[edge[0]].push_back(edge[1]);
    e[edge[1]].push_back(edge[0]);
}

Now when I try to access e using a range based for loop like:

for(vector<int> v: e[node])

I get an error:

no viable conversion from int to vector<int>

Which I guess means I should use:

for(int i: e[node])

How - isn't each element of e a vector?

Upvotes: 0

Views: 716

Answers (1)

lilucpp
lilucpp

Reputation: 306

each element of e is a vector, each element of e[node] is int.

Upvotes: 1

Related Questions