| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 안드로이드 파일
- application not responding
- android support
- 백준
- java
- 안드로이드
- 백준 알고리즘
- 너비우선탐색
- BFS
- android adapterview
- 소수
- db
- support fragment
- 자바 컬렉션
- oracle
- 안드로이드 ANR
- 알고리즘
- android fragment
- 액티비티 ANR
- support 라이브러리
- DFS
- 안드로이드 AdapterView
- 컬렉션
- 소수 알고리즘
- anr
- 깊이우선탐색
- Github
- SQLite와 Realm 차이점
- 안드로이드 DBMS
- 자료구조
Archives
- Today
- Total
밍의 기록들😉
[문제] 웜바이러스 2606번 본문
문제
https://www.acmicpc.net/problem/2606
소스코드
import java.util.Scanner;
public class Virus {
private static int v;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
v = sc.nextInt(); // node, vertex
int e = sc.nextInt(); // edge
sc.nextLine();
int[][] graph = new int[v][v];
int[] check = new int[v];
for(int i=0; i<e; i++){
String[] input = sc.nextLine().split(" ");
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[1]);
graph[a-1][b-1] = 1; // 인접행렬을 통해 관계 표시
graph[b-1][a-1] = 1;
}
dfs(0, graph, check);
int cnt = 0;
for(int i=1; i<v; i++){
if(check[i] == 1)
cnt++;
}
System.out.println(cnt);
}
private static void dfs(int i, int[][] graph, int[] check) {
check[i] = 1;
for(int j=0; j<v; j++){
if(graph[i][j] == 1 && check[j] !=1){
dfs(j, graph, check);
}
}
}
}
풀이
-
'자료구조, 알고리즘 > 문제풀이' 카테고리의 다른 글
| [문제] 깊이우선탐색과 너비우선탐색 (0) | 2018.09.09 |
|---|---|
| [문제] 부등호 2529번 (0) | 2018.09.05 |
| [문제] 이진 패턴 (0) | 2018.09.04 |
| [문제] 자연수의 분할 (4) | 2018.09.04 |
| [문제] 단지번호 붙이기 2667번 (0) | 2018.08.27 |
Comments