I'm trying to create an adjacency list from an input of vertices, edges and single connections. The input looks like this:
3 2 (vertices, edges)
1 2 (connection)
1 3
Right now, my code is
int vertices, edges;
scanf("%d %d", &vertices, &edges);
vector<vector<int>> storage[vertices+1];
for (int i = 0; i < edges; i++) {
int a, b;
scanf("%d %d", &a, &b);
if (find(storage[b].begin(), storage[b].end(), a) != storage[b].end() == false) {
storage[b].push_back(a);
}
if (find(storage[a].begin(), storage[a].end(), b) != storage[a].end() == false) {
storage[a].push_back(b);
}
}
Is there a faster/more efficient way to do this, or is this the best way?