Algorithm/Theory (1) 썸네일형 리스트형 DFS / BFS [ 인접행렬과 인접리스트 ] - 인접행렬 : 정점 int[][] a = new int[n + 1][n + 1]; for (int i = 0; i < m; i++) { int v1 = sc.nextInt(); int v2 = sc.nextInt(); a[v1][v2] = 1; a[v2][v1] = 1; } 인접행렬은 정점(V)이 n개일때 N*N 이차원 배열로 나타낼수 있고 일반적으로 a라고 이름을 짓는다. a[1][5] = 1 의 의미는 정점 1과 정점 5의 간선이 연결되어 있다는 뜻이다.(무방향이기에 a[5][1]도 1) 인접행렬의 값이 1이라면, 정점간의 간선이 존재한다는 것이고, 0이라면 존재하지 않는다는 것이다. (현재는 가중치가 없지만, 가중치를 넣을 때는 1 대신 가중치를 넣으면 됨) - 인접리.. 이전 1 다음