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
inttovector<int>
Which I guess means I should use:
for(int i: e[node]) How - isn't each element of e a vector?
e, you're iterating over one element ofe(a vector), and each element of that element ofeis anint.eis a vector, so shouldn't I have to usevector<int>instead of justint?for (const std::vector<int>& edge : edges)orfor (const auto& edge : edges)would avoid unnecessary copies over yourfor(vector<int> edge : edges).