Created
August 22, 2018 07:24
-
-
Save ajx42/39923f6541abb026fd5e642c0c331549 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 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