• 문제 링크
11255번: ITAI Virus
“Insane Transferable Abnormal Illness” or ITAI for short, is a new viral disease first discovered in a southern part of some city. The symptom is that persons contract with virus will continuously and uncontrollably scream “Itai, itai!” When this v
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int t = read();
while (t-- > 0) {
int n = read() + 1, m = read(), k = read();
Node[] graph = new Node[n];
while (n-- > 1) graph[n] = new Node(n);
while (m-- > 0) {
int a = read(), b = read();
graph[a].adj.add(b);
graph[b].adj.add(a);
}
Set<Integer> set = new HashSet<>();
while (k-- > 0) {
int v = read();
set.add(v);
set.addAll(graph[v].adj);
}
sb.append(set.size()).append("\n");
}
bw.write(sb.toString());
bw.flush();
}
private static class Node {
int src;
List<Integer> adj;
Node(int src) {
this.src = src;
adj = new ArrayList<>();
}
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 27940 가지 산사태 - Greedy / Java (0) | 2024.02.11 |
---|---|
[백준] 27563 Moo Operations - Greedy / Java (0) | 2024.02.10 |
[백준] 10328 Jury Jeopardy - Graph Theory / Java (0) | 2024.02.08 |
[백준] 8073 Road Net - Graph Theory / Java (0) | 2024.02.07 |
[백준] 17848 Flight Turbulence - Graph Theory / Java (0) | 2024.02.06 |
댓글