Created
August 22, 2018 07:25
-
-
Save ajx42/c0ca2c3e448dc8db141c4ac2789bc542 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adjacency List in Vector | |
*/ | |
vector <vector <int> > adj_list; | |
int main(){ | |
int num_nodes, num_edges; | |
cin >> num_nodes >> num_edges; | |
adj_list.resize(num_nodes+1); | |
for(int i = 0, u, v; i < num_edges; ++i){ | |
// take nodes between which we have an edge | |
cin >> u >> v; | |
// undirected so we push v to list of u and vice versa | |
adj_list[u].push_back(v); | |
adj_list[v].push_back(u); | |
} | |
// do something with the graph | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment