-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2642931
commit 3ac0075
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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
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; | ||
} | ||
} |