Skip to content

Instantly share code, notes, and snippets.

@ajx42
Created August 22, 2018 07:25
Show Gist options
  • Save ajx42/c0ca2c3e448dc8db141c4ac2789bc542 to your computer and use it in GitHub Desktop.
Save ajx42/c0ca2c3e448dc8db141c4ac2789bc542 to your computer and use it in GitHub Desktop.
/*
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