Last active
October 22, 2016 17:54
-
-
Save ssi-anik/3a399b718413c3b614b7c6c21c84fd48 to your computer and use it in GitHub Desktop.
bfs example
This file contains hidden or 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
| #include<stdio.h> | |
| #include<string.h> | |
| int main(){ | |
| freopen("graph-representation.txt", "r", stdin); | |
| int graph[100][100]; | |
| int node, edge; | |
| memset(graph, 0, sizeof(graph)); | |
| scanf("%d %d", &node, &edge); | |
| int i, j; | |
| for(i = 1; i <= edge; ++i){ | |
| int con_1, con_2; | |
| scanf("%d %d", &con_1, &con_2); | |
| graph[con_1][con_2] = 1; | |
| graph[con_2][con_1] = 1; | |
| } | |
| for(i = 1; i <= node; ++i){ | |
| for(j = 1; j <= node; ++j){ | |
| printf("%5d ", graph[i][j]); | |
| } | |
| printf("\n"); | |
| } | |
| return 0; | |
| } |
This file contains hidden or 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
| 11 10 | |
| 1 2 | |
| 1 3 | |
| 1 4 | |
| 3 5 | |
| 3 6 | |
| 4 7 | |
| 5 8 | |
| 6 9 | |
| 6 10 | |
| 6 11 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment