Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 투포인터
- oracle
- BFS
- MySQL
- binary search
- SQL
- 알고리즘
- DP
- COS PRO
- 코딩테스트
- 코테
- 건강
- BOJ
- 러닝일지
- math
- 문자열
- 문제풀이
- 백준
- 프로그래머스
- priorityqueue
- 문제해결
- Java
- 이분탐색
- dfs
- greedy
- SWEA
- 운동기록
- 자바
- db
- 시뮬레이션
Archives
- Today
- Total
슈콩
[BOJ] 2606 바이러스 본문
[문제]
https://www.acmicpc.net/problem/2606
[소스 코드]
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
int m = Integer.parseInt(br.readLine());
int[] map = new int[n+1];
boolean[][] visit = new boolean[n+1][n+1];
for(int i=0;i<m;i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
visit[a][b] = visit[b][a] = true;
}
Queue<Integer> q = new LinkedList<>();
boolean[] check = new boolean[n+1];
q.offer(1);
check[1] = true;
int result = 0;
while(!q.isEmpty()) {
int curr = q.poll();
for(int i=1;i<=n;i++) {
if(visit[curr][i] && !check[i]) {
check[i] = true;
q.offer(i);
result++;
}
}
}
System.out.println(result);
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 2664 촌수계산 (0) | 2026.01.22 |
|---|---|
| [BOJ] 2667 단지번호붙이기 (0) | 2026.01.22 |
| [BOJ] 2178 미로 탐색 (0) | 2026.01.09 |
| [BOJ] 1260 DFS와 BFS (3) | 2026.01.08 |
| [BOJ] 19236 청소년 상어 (0) | 2025.12.17 |