Skip to content

Instantly share code, notes, and snippets.

@ajx42
Created August 22, 2018 07:24
Show Gist options
  • Save ajx42/39923f6541abb026fd5e642c0c331549 to your computer and use it in GitHub Desktop.
Save ajx42/39923f6541abb026fd5e642c0c331549 to your computer and use it in GitHub Desktop.
/*
Adjacency Matrix Representation
*/
// undirected dense graph (with lesser nodes eg N = 1e3)
int adj_matrix[N][N];
int main(){
int num_nodes, num_edges;
cin >> num_nodes >> num_edges;
for(int i = 0, u, v; i < num_edges; ++i){
// take nodes between which we have an edge
cin >> u >> v;
// undirected so we mark both (u, v) and (v, u) as 1
adj_matrix[u][v] = 1;
adj_matrix[v][u] = 1;
}
// do something with the graph
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment