From 556c4d62a7f35cf93d133a2b8e8d3e9ae7a52177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8B=A0=EC=A7=80?= <101992179+ksinji@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:50:30 +0900 Subject: [PATCH] =?UTF-8?q?[20251013]=20PGM=20/=20LV3=20/=20=EA=B0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=A8=BC=20=EB=85=B8=EB=93=9C=20/=20=EA=B0=95?= =?UTF-8?q?=EC=8B=A0=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \353\250\274 \353\205\270\353\223\234.md" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "ksinji/202510/13 PGM \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" diff --git "a/ksinji/202510/13 PGM \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" "b/ksinji/202510/13 PGM \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" new file mode 100644 index 00000000..71c02561 --- /dev/null +++ "b/ksinji/202510/13 PGM \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" @@ -0,0 +1,47 @@ +```java +import java.util.*; + +class Solution { + public int solution(int n, int[][] edge) { + List> graph = new ArrayList<>(); + + for (int i = 0; i <= n; i++) { + graph.add(new ArrayList<>()); + } + + for (int[] e : edge) { + graph.get(e[0]).add(e[1]); + graph.get(e[1]).add(e[0]); + } + + int[] dist = new int[n+1]; + Arrays.fill(dist, -1); + + Queue q = new LinkedList<>(); + q.add(1); + dist[1] = 0; + + while (!q.isEmpty()) { + int cur = q.poll(); + for (int next : graph.get(cur)) { + if (dist[next] == -1) { + dist[next] = dist[cur] + 1; + q.add(next); + } + } + } + + int max = Integer.MIN_VALUE; + + for (int d : dist) { + if (d > max) max = d; + } + + int answer = 0; + + for (int d : dist) if (d == max) answer++; + + return answer; + } +} +```