forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproDFS2.java
More file actions
48 lines (34 loc) · 926 Bytes
/
proDFS2.java
File metadata and controls
48 lines (34 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class proDFS2 {
static boolean value[][];
static int answer =0;
public static void main(String[] args) {
int n = 3;
int computers[][] = {{1,1,0}, {1,1,0}, {0,0,1}};
System.out.println(solution(n, computers));
}
public static int solution(int n, int[][] computers) {
value = new boolean[n][n];
for(int i=0; i<n; i++)
{
if(!value[i][i])
{
DFS(i,n,computers);
answer++;
}
}
return answer;
}
//n=3
public static void DFS(int start, int depth, int[][] computers)
{
for(int i= 0; i< depth; i++)
{
if(computers[start][i] == 1 && !value[start][i])
{
value[i][start] = true;
value[start][i] = true;
DFS(i,depth,computers);
}
}
}
}