-
Notifications
You must be signed in to change notification settings - Fork 0
/
바이러스.java
42 lines (34 loc) · 1.1 KB
/
바이러스.java
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
import java.util.*;
import java.io.*;
public class Main {
//컴퓨터 수
public static int V;
// 연결 수
public static int E;
public static boolean[] visit=new boolean[101];
public static int[][] arr=new int[101][101];
public static int cnt=0;
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
V=Integer.parseInt(br.readLine());
E=Integer.parseInt(br.readLine());
for(int i=0;i<E;i++){
StringTokenizer st=new StringTokenizer(br.readLine()," ");
int a=Integer.parseInt(st.nextToken());
int b=Integer.parseInt(st.nextToken());
arr[a][b]=1;
arr[b][a]=1;
}
System.out.print( DFS(1));
}
private static int DFS(int start){
visit[start]=true;
for(int i=1;i<arr.length;i++){
if(arr[start][i]==1 && visit[i]==false){
cnt+=1;
DFS(i);
}
}
return cnt;
};
}