From b7d901951afb58ea127931a51b03ec043ece207a Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Sun, 5 Oct 2025 22:49:00 +0900 Subject: [PATCH] =?UTF-8?q?[20251005]=20BOJ=20/=20G4=20/=20=EA=B1=B0?= =?UTF-8?q?=EC=A7=93=EB=A7=90=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\261\260\354\247\223\353\247\220.md" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "suyeun84/202510/05 BOJ G4 \352\261\260\354\247\223\353\247\220.md" diff --git "a/suyeun84/202510/05 BOJ G4 \352\261\260\354\247\223\353\247\220.md" "b/suyeun84/202510/05 BOJ G4 \352\261\260\354\247\223\353\247\220.md" new file mode 100644 index 00000000..97e9d6b1 --- /dev/null +++ "b/suyeun84/202510/05 BOJ G4 \352\261\260\354\247\223\353\247\220.md" @@ -0,0 +1,72 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception { st = new StringTokenizer(br.readLine()); } + static int nextInt() { return Integer.parseInt(st.nextToken()); } + + static int N, M; + static int[] parent; + static List parties = new ArrayList<>(); + + public static void main(String[] args) throws Exception { + nextLine(); + N = nextInt(); + M = nextInt(); + + parent = new int[N + 1]; + for (int i = 1; i <= N; i++) parent[i] = i; + + nextLine(); + int T = nextInt(); + int[] truth = new int[T]; + for (int i = 0; i < T; i++) truth[i] = nextInt(); + + for (int i = 0; i < M; i++) { + nextLine(); + int cnt = nextInt(); + int[] attendees = new int[cnt]; + for (int j = 0; j < cnt; j++) attendees[j] = nextInt(); + parties.add(attendees); + + for (int j = 1; j < cnt; j++) { + union(attendees[0], attendees[j]); + } + } + + boolean[] truthRoot = new boolean[N + 1]; + for (int t : truth) { + truthRoot[find(t)] = true; + } + + int answer = 0; + for (int[] party : parties) { + boolean canLie = true; + for (int p : party) { + if (truthRoot[find(p)]) { + canLie = false; + break; + } + } + if (canLie) answer++; + } + + System.out.println(answer); + } + + static int find(int x) { + if (x == parent[x]) return x; + return parent[x] = find(parent[x]); + } + + static void union(int x, int y) { + x = find(x); + y = find(y); + if (x == y) return; + parent[y] = x; + } +} +```