From 7c1f46b4de07f32a615e45fff0ed0f8afad23e98 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Wed, 19 Nov 2025 23:00:08 +0900 Subject: [PATCH] =?UTF-8?q?[20251119]=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=EC=9D=B4?= =?UTF-8?q?=EA=B0=95=ED=98=84?= 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" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "lkhyun/202511/19 PGM Lv3 \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" diff --git "a/lkhyun/202511/19 PGM Lv3 \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" "b/lkhyun/202511/19 PGM Lv3 \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" new file mode 100644 index 00000000..c8617985 --- /dev/null +++ "b/lkhyun/202511/19 PGM Lv3 \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" @@ -0,0 +1,48 @@ +```java +import java.util.*; +class Solution { + static int answer = 0; + static int max = 0; + static List[] adjList; + public int solution(int n, int[][] edge) { + answer = 0; + adjList = new List[n+1]; + for(int i = 0; i<=n; i++){ + adjList[i] = new ArrayList<>(); + } + + for(int[] e : edge){ + int a = e[0]; + int b = e[1]; + adjList[a].add(b); + adjList[b].add(a); + } + + BFS(n); + + return answer; + } + public static void BFS(int n){ + ArrayDeque q = new ArrayDeque<>(); + boolean[] visited = new boolean[n+1]; + q.offer(new int[]{1,0}); + visited[1] = true; + + while(!q.isEmpty()){ + int[] cur = q.poll(); + if(max < cur[1]){ + max = cur[1]; + answer = 1; + }else if(max == cur[1]){ + answer++; + } + for(int next : adjList[cur[0]]){ + if(!visited[next]){ + q.offer(new int[]{next,cur[1]+1}); + visited[next] = true; + } + } + } + } +} +```