Skip to content

Instantly share code, notes, and snippets.

@ssi-anik
Last active October 22, 2016 17:54
Show Gist options
  • Select an option

  • Save ssi-anik/3a399b718413c3b614b7c6c21c84fd48 to your computer and use it in GitHub Desktop.

Select an option

Save ssi-anik/3a399b718413c3b614b7c6c21c84fd48 to your computer and use it in GitHub Desktop.
bfs example
#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;
}
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