Skip to content

Commit

Permalink
Baekjoon #13023
Browse files Browse the repository at this point in the history
  • Loading branch information
allrightDJ0108 committed Aug 14, 2023
1 parent 2642931 commit 3ac0075
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Binary file not shown.
64 changes: 64 additions & 0 deletions CodingTestStudy1.0/src/GraphTheory/Problem13023.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package GraphTheory;

import java.io.*;
import java.util.*;

public class Problem13023 {

static int N, M;
//static int[][] arr;
static ArrayList<Integer>[] list;
static boolean[] visited;
static int result = 0;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer str = new StringTokenizer(br.readLine(), " ");

N = Integer.parseInt(str.nextToken());
M = Integer.parseInt(str.nextToken());

//arr = new int[N][N];
list = new ArrayList[N];
visited = new boolean[N];

for (int i=0; i<N; i++) {
list[i] = new ArrayList<Integer>();
}

for (int i = 0; i < M; i++) {
str = new StringTokenizer(br.readLine(), " ");
int x = Integer.parseInt(str.nextToken());
int y = Integer.parseInt(str.nextToken());
list[x].add(y);
list[y].add(x);
}

// dfs
for (int i = 0; i < N; i++) {
if (result == 0) {
dfsFn(i, 1);
}

}

System.out.println(result);
}

static void dfsFn(int x, int count) {

//ABCDE가 친구이려면 깊이가 5여야 함
if (count == 5) {
result = 1;
return;
}

visited[x] = true;
for (int j : list[x]) {
if (!visited[j]) {
dfsFn(j, count+1);
}
}
visited[x] = false;
}
}

0 comments on commit 3ac0075

Please sign in to comment.