[algo] DFS (Depth First Search)

#include 
int n; //접점
int map[30][30], visit[30];
void DFS(int v)
{
int i;

visit[v] = 1; //노드 v 방문
for (i=1; i<=n; i++)
{
if (map[v][i]==1 && !visit[i])
{
printf("from %d to %d n",v,i);
DFS(i);
}
}
}
void main ()
{
int start;
int v1, v2;
int edge_num;

scanf("%d%d%d",&n,&start,&edge_num);

int j;
for(j=0; j {
scanf("%d%d",&v1,&v2);
map[v1][v2] = 1;
map[v2][v1] = 1;
}
DFS(start);
}

“[algo] DFS (Depth First Search)” Posted first on ” Programming on Medium “
Author: peter_yun

Author: Pawan Kumar

Leave a Reply

Close Menu
%d bloggers like this:
Skip to toolbar