<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>eunzi.log</title>
        <link>https://velog.io/</link>
        <description>백엔드 개발자가 되고싶은 eunzi😊</description>
        <lastBuildDate>Wed, 25 Jun 2025 01:29:40 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>eunzi.log</title>
            <url>https://velog.velcdn.com/images/eunzi_code/profile/5771c9f9-824a-4fce-954a-0c49b029bd6c/image.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. eunzi.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/eunzi_code" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[백준 15650번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-15650%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-15650%EB%B2%88Java</guid>
            <pubDate>Wed, 25 Jun 2025 01:29:40 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/a4ed33f7-4e79-4496-8dfc-9237114ef2df/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {

    public static int[] arr;
    public static int N,M;
    public static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        N = Integer.parseInt(st.nextToken());
        M = Integer.parseInt(st.nextToken());

        arr = new int[M];

        dfs(1,0);
        System.out.println(sb);
    }

    public static void dfs(int at, int depth) {
        if(depth == M) {
            for(int val:arr) {
                sb.append(val).append(&#39; &#39;);
            }
            sb.append(&#39;\n&#39;);
            return;
        }

        for(int i=at; i&lt;=N; i++) {
            arr[depth] = i;
            dfs(i+1, depth+1);
        }
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 14500번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-14500%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-14500%EB%B2%88Java</guid>
            <pubDate>Wed, 18 Jun 2025 00:17:32 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/315811e1-904e-4386-a699-144d98314db1/image.png" alt=""><img src="https://velog.velcdn.com/images/eunzi_code/post/d6fd9cb6-d4c4-41b5-99c5-e1bf34a8480b/image.png" alt=""></p>
<pre><code class="language-java">import java.util.*;
import java.io.*;

public class Main {
    static int N, M, answer;
    static int[] dx = { -1, 0, 1,  0 };
    static int[] dy = {  0, 1, 0, -1 };
    static int[][] map;
    static boolean[][] visited;

    public void DFS(int x, int y, int sum, int L) {
        if (L == 3) {
            answer = Math.max(answer, sum);
            return;
        }

        for (int i = 0; i &lt; 4; i++) {
            int nextX = x + dx[i];
            int nextY = y + dy[i];

            if (nextX &lt; 0 || nextX &gt; N - 1 || nextY &lt; 0 || nextY &gt; M - 1) continue;

            if (!visited[nextX][nextY]) {
                // ㅜ 테트로미노 만들기 위해 1번째 칸에서 탐색을 한 번 더 진행
                if (L == 1) {
                    visited[nextX][nextY] = true;
                    DFS(x, y, sum + map[nextX][nextY], L + 1);
                    visited[nextX][nextY] = false;
                }

                visited[nextX][nextY] = true;
                DFS(nextX, nextY, sum + map[nextX][nextY], L + 1);
                visited[nextX][nextY] = false;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        Main main = new Main();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        N = Integer.parseInt(st.nextToken());
        M = Integer.parseInt(st.nextToken());

        map = new int[N][M];
        visited = new boolean[N][M];

        for (int i = 0; i &lt; N; i++) {
            st = new StringTokenizer(br.readLine());
            for (int j = 0; j &lt; M; j++) {
                map[i][j] = Integer.parseInt(st.nextToken());
            }
        }

        for (int i = 0; i &lt; N; i++) {
            for (int j = 0; j &lt; M; j++) {
                visited[i][j] = true;
                main.DFS(i, j, map[i][j], 0);
                visited[i][j] = false;
            }
        }

        System.out.println(answer);
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 9019번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-9019%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-9019%EB%B2%88Java</guid>
            <pubDate>Tue, 17 Jun 2025 13:19:39 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/db137848-a99e-4fc5-95a0-dcf931637d56/image.png" alt=""><img src="https://velog.velcdn.com/images/eunzi_code/post/55f11dc8-59ab-4f1d-9251-bf8286519936/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());

        while (t-- &gt; 0) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());

            Queue&lt;Integer&gt; q = new LinkedList&lt;&gt;();
            boolean[] visited = new boolean[10000]; // BFS 탐색의 방문 여부 체크
            String[] command = new String[10000]; // 정답 명령어를 담는 배열


            q.add(a); // a를 큐에 담고
            visited[a] = true; // 방문 표시한다
            Arrays.fill(command,  &quot;&quot;); // 꼭 넣어야하나? 안넣으면 틀림


            while (!q.isEmpty() &amp;&amp; !visited[b]) {
                int now = q.poll(); // 큐에서 값을 뺀다 = 현재 탐색 위치

                int D = (2 * now) % 10000; // n을 두배로 바꾸고 10000으로 나눈 나머지
                int S = now == 0 ? 9999 : now - 1; // 0일 때, 9999, 아니면 1을 빼준다 
                int L = (now % 1000) * 10 + now / 1000; // 1234 -&gt; 2341 : 1234를 1000으로 나눈 나머지(234)에 10을 곱함=2340, 1234를 1000으로 나누면 1, 2340+1=2341
                int R = (now % 10) * 1000 + now / 10; // 1234 -&gt; 4123 : 1234를 10으로 나눈 나머지에 1000 곱합 = 4000, 1234를 10으로 나누면 123, 4000+123=4123

                if (!visited[D]) {
                    q.add(D); // 큐에 넣는다
                    visited[D] = true; // 방문처리한다
                    command[D] = command[now] + &quot;D&quot;; // 명령어를 추가한다
                }

                if (!visited[S]) {
                    q.add(S);
                    visited[S] = true;
                    command[S] = command[now] + &quot;S&quot;;
                }

                if (!visited[L]) {
                    q.add(L);
                    visited[L] = true;
                    command[L] = command[now] + &quot;L&quot;;
                }

                if (!visited[R]) {
                    q.add(R);
                    visited[R] = true;
                    command[R] = command[now] + &quot;R&quot;;
                }
            }
            System.out.println(command[b]);
        }
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 7662번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-7662%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-7662%EB%B2%88Java</guid>
            <pubDate>Mon, 16 Jun 2025 09:04:16 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/d32b7b3d-745c-4fc8-8d2f-1f21f9a0bf6e/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = null;
    StringBuilder sb = new StringBuilder();

    int T = Integer.parseInt(in.readLine());

    for (int tc = 0; tc &lt; T; tc++) {
        TreeMap&lt;Integer, Integer&gt; map = new TreeMap&lt;&gt;();
        int k = Integer.parseInt(in.readLine());

        for (int i = 0; i &lt; k; i++) {
            st = new StringTokenizer(in.readLine());

            char c = st.nextToken().charAt(0);
            int n = Integer.parseInt(st.nextToken());

            // n을 트리맵에 삽입
            if (c == &#39;I&#39;) {
                map.put(n, map.getOrDefault(n, 0) + 1);
            }
            // 맵이 비어있는 경우
            else if (map.size() == 0) {
                continue;
            }
            // 최댓값 또는 최솟값 삭제
            else {
                int key = n == 1 ? map.lastKey() : map.firstKey();
                int cnt = map.get(key);

                if (cnt == 1) {
                    map.remove(key);
                } else {
                    map.put(key, cnt - 1);
                }
            }
        }

        if (map.size() == 0) {
            sb.append(&quot;EMPTY\n&quot;);
        } else {
            sb.append(map.lastKey()).append(&quot; &quot;).append(map.firstKey()).append(&quot;\n&quot;);
        }
    }

    System.out.println(sb.toString());
}
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 16928번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-16928%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-16928%EB%B2%88Java</guid>
            <pubDate>Thu, 12 Jun 2025 01:14:42 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/d6829b7c-6b54-4208-9481-6729806a9200/image.png" alt=""><img src="https://velog.velcdn.com/images/eunzi_code/post/0703d4dc-a6c1-4339-aac9-e3f83a256dc7/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;
public class Main{
    static int arr[],N,M;
    static boolean visit[];
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        N = Integer.parseInt(st.nextToken());
        M = Integer.parseInt(st.nextToken());
        arr = new int[101];
        visit = new boolean[101];

        for(int i=0; i&lt;N+M; i++){
            st = new StringTokenizer(br.readLine());
            int x =Integer.parseInt(st.nextToken());
            int y =Integer.parseInt(st.nextToken());
            arr[x]=y;
        }

        bfs(1);
    }
    static void bfs(int start){
        Queue&lt;int[]&gt;q=new LinkedList&lt;&gt;();
        q.add(new int[]{start,0});
        visit[start]=true;

        while(!q.isEmpty()){
            int p[] = q.poll();

            if(p[0]==100){
                System.out.println(p[1]);
                return;
            }

            for(int i=1; i&lt;7; i++){
                int next = p[0]+i;
                if(next&lt;=100){
                    if(arr[next]!=0){
                        next = arr[next];
                    }
                    if(!visit[next]){
                        visit[next] = true;
                        q.add(new int[]{next,p[1]+1});

                    }
                }
            }
        }
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 10026번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-10026%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-10026%EB%B2%88Java</guid>
            <pubDate>Wed, 11 Jun 2025 04:42:31 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/22f45398-4dc4-4cbd-b6f4-d0cc781072dd/image.png" alt=""><img src="https://velog.velcdn.com/images/eunzi_code/post/e33b220a-b00a-4524-9f66-66a19fbbedae/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {

    static int N;
    static String S;
    static char[][] arr;
    static boolean[][] visits;
    static int[] dx = {-1, 0, 0, 1};
    static int[] dy = {0, 1, -1, 0};

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        N = Integer.parseInt(br.readLine());
        arr = new char[N + 1][N + 1];
        visits = new boolean[N + 1][N + 1];

        for (int i = 0; i &lt; N; i++) {
            S = br.readLine(); // RRRBB
            for (int j = 0; j &lt; N; j++) {
                arr[i][j] = S.charAt(j); // R R R B B
            }
        }

        // 정상인 경우
        int cnt = 0;
        for (int i = 0; i &lt; N; i++) {
            for (int j = 0; j &lt; N; j++) {
                if (!visits[i][j]) {
                    dfs(i, j);
                    cnt++;
                }
            }
        }
        int normal_cnt = cnt;
        cnt = 0;
        visits = new boolean[N + 1][N + 1];

        // 비정상인 경우
        // G를 R로 바꿔주고 돌린다.

        for (int i = 0; i &lt; N; i++) {
            for (int j = 0; j &lt; N; j++) {
                if (arr[i][j] == &#39;G&#39;) {
                    arr[i][j] = &#39;R&#39;; // G를 R로 바꿔준다.
                }
            }
        }

        for (int i = 0; i &lt; N; i++) {
            for (int j = 0; j &lt; N; j++) {
                if (!visits[i][j]) {
                    dfs(i, j);
                    cnt++;
                }
            }
        }
        int abnormal_cnt = cnt;
        System.out.println(normal_cnt + &quot; &quot; + abnormal_cnt);

    }

    public static void dfs(int x, int y) {
        visits[x][y] = true;
        char tmp_char = arr[x][y]; // R
        for (int i = 0; i &lt; 4; i++) {
            int new_x = x + dx[i];
            int new_y = y + dy[i];

            if (new_x &lt; 0 || new_y &lt; 0 || new_x &gt; N || new_y &gt; N) {
                continue;
            }

            if (!visits[new_x][new_y] &amp;&amp; arr[new_x][new_y] == tmp_char) {
                dfs(new_x, new_y);
            }
        }
    }

}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 7576번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-7576%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-7576%EB%B2%88Java</guid>
            <pubDate>Sun, 08 Jun 2025 23:56:42 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/3ee6f9c5-149b-43b3-816d-935932d99d64/image.png" alt=""><img src="https://velog.velcdn.com/images/eunzi_code/post/d4188915-33d8-4333-8457-0f24461ac8c8/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {
    static int N; // 세로 칸의 수
    static int M; // 가로 칸의 수
    static int[][] graph; // 그래프배열
    static boolean[][] visited; //방문한 자리
    static int count = 0; // 최소 날짜
    static int[] dx = {0, 0, 1, -1};
    static int[] dy = {1, -1, 0, 0};
    static Queue&lt;int[]&gt; q = new LinkedList&lt;&gt;();

    public static void main(String[] args) throws Exception {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine(), &quot; &quot;);


        M = Integer.parseInt(st.nextToken()); // 세로 칸  초기화
        N = Integer.parseInt(st.nextToken()); // 가로 칸 초기화

        // 그래프 초기화
        graph = new int[N][M];
        for (int i = 0; i &lt; N; i++) {
            st = new StringTokenizer(br.readLine(), &quot; &quot;);
            for (int j = 0; j &lt; M; j++) {
                graph[i][j] = Integer.parseInt(st.nextToken());
                if (graph[i][j] == 1) { // 1일 경우 큐에 삽입
                    q.add(new int[]{i, j});
                }
            }
        }
        System.out.println(bfs());
    }

    public static int bfs() {
        while (!q.isEmpty()) { // 큐가 다 빌때까지 실행
            int[] tmp = q.poll();
            int x = tmp[0];
            int y = tmp[1];
            // 4방 탐색
            for (int i = 0; i &lt; 4; i++) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                //그래프 범위 안에 있을 경우
                if (nx &gt;= 0 &amp;&amp; ny &gt;= 0 &amp;&amp; nx &lt; N &amp;&amp; ny &lt; M) {
                    if (graph[nx][ny] == 0) {
                        q.add(new int[]{nx, ny});
                        graph[nx][ny] = graph[x][y] + 1; // 새로 추가된 곳은 원래 있던 수 + 1
                        // 그 이유는 날짜를 세기 위해
                    }
                }
            }
        }

        for (int i = 0; i &lt; N; i++) {
            for (int j = 0; j &lt; M; j++) {
                if (graph[i][j] == 0) { // 그래프안에 0 이 존재하면 답은 -1
                    return -1;
                }
                // 그래프의 날짜중에 가장 큰 수를 찾으면 그것이 최종날짜
                count = Math.max(count, graph[i][j]);
            }
        }

        // 저장될 때부터 모든 토마토가 익어익는상태라면
        if (count == 1) {
            return 0;
        } else { // 아닐 경우 최종날짜 - 1 출력
            return count-1;
        }
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 7569번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-7569%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-7569%EB%B2%88Java</guid>
            <pubDate>Thu, 05 Jun 2025 01:02:11 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/a0d42d00-f9a3-440b-b7cb-ebcbe5708d0f/image.png" alt=""><img src="https://velog.velcdn.com/images/eunzi_code/post/05a968ec-0365-48b0-8fe0-82758b409d49/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {
    static int M, N, H;
    static int[][][] graph;
    // x, y, z축 이동을 위한 델타 배열 선언
    static int[] dx = {-1, 1, 0, 0, 0, 0};
    static int[] dy = {0, 0, -1, 1, 0, 0};
    static int[] dz = {0, 0, 0, 0, -1, 1};
    static Deque&lt;int[]&gt; queue = new ArrayDeque&lt;&gt;();
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        M = Integer.parseInt(st.nextToken());
        N = Integer.parseInt(st.nextToken());
        H = Integer.parseInt(st.nextToken());
        graph = new int[H][N][M];

        // 처음부터 모든 토마토가 익은 상태인지 체크하기 위한 변수 선언
        boolean alreadyFinished = true;

        // 토마토 배열 입력
        for(int k=0; k&lt;H; k++) {
            for(int i=0; i&lt;N; i++) {
                st = new StringTokenizer(br.readLine());
                for(int j=0; j&lt;M; j++) {
                    graph[k][i][j] = Integer.parseInt(st.nextToken());
                    // 만약 익은 토마토라면 큐에 좌표와 일 수 저장
                    if(graph[k][i][j] == 1) {
                        queue.addLast(new int[]{k, i, j, 0});
                    }
                    // 익지 않은 토마토가 한 개라도 있으면 
                    // BFS를 진행할 수 있으므로 flag값 false로 변경
                    if(graph[k][i][j] == 0) {
                        alreadyFinished = false;
                    }
                }
            }
        }

        // 입력부터 더이상 익힐게 없으면 0 출력 후 종료
        if(alreadyFinished) {
            System.out.println(0);
            return;
        }

        // BFS를 수행하고 반환된 결과값 저장
        int answer = bfs();

        // 익지않은 토마토 체크
        // 있다면 정답을 -1로 변경하고 종료
        for (int k = 0; k &lt; H; k++) {
            for (int i = 0; i &lt; N; i++) {
                for (int j = 0; j &lt; M; j++) {
                    if (graph[k][i][j] == 0) {
                        answer = -1;
                        break;
                    }
                }
            }
        }
        System.out.println(answer);
    }

    static int bfs() {
        // 익는데 걸린 일 수를 저장하기 위한 변수 선언
        int day = 0;
        while(!queue.isEmpty()) {
            int[] tmp = queue.removeFirst();
            int z = tmp[0];
            int x = tmp[1];
            int y = tmp[2];
            // 익는데 걸린 일 수 저장
            day = tmp[3];
            for (int i = 0; i &lt; 6; i++) {
                int nz = z + dz[i];
                int nx = x + dx[i];
                int ny = y + dy[i];
                // 범위를 벗어나면 다시 연산
                if (nz &lt; 0 || nx &lt; 0 || ny &lt; 0 || nz &gt;= H || nx &gt;= N || ny &gt;= M) {
                    continue;
                }
                // 익지않은 토마토라면 익히고, 해당 토마토 좌표 및 익는데 걸린 일 수 + 1 큐에 저장
                if (graph[nz][nx][ny] == 0) {
                    graph[nz][nx][ny] = 1;
                    queue.addLast(new int[]{nz, nx, ny, day + 1});
                }
            }
        }
        return day;
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 5430번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-5430%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-5430%EB%B2%88Java</guid>
            <pubDate>Wed, 04 Jun 2025 00:22:55 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/2f36f067-d0c6-48ea-a7e7-7282cde03f93/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {

    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) throws IOException {

        ArrayDeque&lt;Integer&gt; deque;
        StringTokenizer st;

        int T = Integer.parseInt(br.readLine());

        while(T --&gt; 0) {

            String command = br.readLine();    // 문제에서 p에 해당하는 명령어
            int n = Integer.parseInt(br.readLine());

            st = new StringTokenizer(br.readLine(), &quot;[],&quot;);

            deque = new ArrayDeque&lt;Integer&gt;();

            // 덱에 배열 원소를 넣어준다.
            for(int i = 0; i &lt; n; i++) {
                deque.add(Integer.parseInt(st.nextToken()));
            }

            AC(command, deque);
        }

        System.out.println(sb);

    }

    public static void AC(String command, ArrayDeque&lt;Integer&gt; deque) {

        boolean isRight = true;

        for(char cmd : command.toCharArray()) {

            if(cmd == &#39;R&#39;) {
                isRight = !isRight;    // 방향을 바꿔준다.
                continue;
            }

            // 아래는 D의 경우
            // D 함수이면서 isRight가 true 일 경우
            if(isRight) {
                // 만약 반환 된 원소가 없을 경우 error를 출력하도록 하고 함수 종료
                if(deque.pollFirst() == null) {
                    sb.append(&quot;error\n&quot;);
                    return;
                }
            }
            else {
                // 만약 반환 된 원소가 없을 경우 error를 출력하도록 하고 함수 종료
                if(deque.pollLast() == null) {
                    sb.append(&quot;error\n&quot;);
                    return;
                }    
            }
        }

        // 모든 함수들이 정상적으로 작동했다면 덱의 남은 요소들을 출력문으로 만들어준다.
        makePrintString(deque, isRight);
    }

    public static void makePrintString(ArrayDeque&lt;Integer&gt; deque, boolean isRight) {

        sb.append(&#39;[&#39;);    // 여는 대괄호 먼저 StringBuilder에 저장

        if(deque.size() &gt; 0) {    //만약 출력 할 원소가 한 개 이상일 경우
            if(isRight) {    // 정방향일경우 
                sb.append(deque.pollFirst());    // 먼저 첫 번째 원소를 넘겨준다.

                // 그 다음 원소부터 반점을 먼저 넘겨준 후 덱의 원소를 하나씩 뽑아 넘긴다. 
                while(!deque.isEmpty()) {
                    sb.append(&#39;,&#39;).append(deque.pollFirst());
                }
            }
            else {    // 역방향일경우 
                sb.append(deque.pollLast());    // 먼저 뒤에서부터 첫 번째 원소를 넘겨준다.

                // 그 다음 원소부터 반점을 먼저 넘겨준 후 덱의 원소를 뒤에서부터 하나씩 뽑아 넘긴다. 
                while(!deque.isEmpty()) {
                    sb.append(&#39;,&#39;).append(deque.pollLast());
                }
            }
        }

        sb.append(&#39;]&#39;).append(&#39;\n&#39;);    // 닫는 대괄호 및 개행으로 마무리
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 1931번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-1931%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-1931%EB%B2%88Java</guid>
            <pubDate>Mon, 02 Jun 2025 01:20:14 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/c80dc187-cf16-4bde-a004-fb6a306715ee/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[][] arr = new int[n][2];
        for (int i = 0; i &lt; n; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            arr[i][0] = Integer.parseInt(st.nextToken());
            arr[i][1] = Integer.parseInt(st.nextToken());
        }

        Arrays.sort(arr, new Comparator&lt;int[]&gt;() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[1] == o2[1]) { //회의 끝나는 시간이 같다면
                    return o1[0] - o2[0]; //회의 시작 시간 빠른순 정렬
                } else {
                    return o1[1] - o2[1]; //같지 않으면 회의 끝나는 시간 빠른순 정렬
                }
            }
        });

        int cnt = 1; // 하단에 첫번째 회의를 이미 count 함
        int min = arr[0][1]; // 정렬한 배열에서 첫번째 회의 끝나는 시간
        for (int i = 1; i &lt; n; i++) {
            if (arr[i][0] &gt;= min) { // 다음 회의 시작 시간이 회의 첫번째 회의 끝나는 시간보다 크거나 같다면
                min = arr[i][1]; // 회의 끝나는 시간 다시 세팅
                cnt++;
            }
        }

        System.out.println(cnt);
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 1074번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-1074%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-1074%EB%B2%88Java</guid>
            <pubDate>Sun, 01 Jun 2025 03:54:11 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/0662ba1e-267a-4da1-a1e3-edac3aa303bf/image.png" alt=""><img src="https://velog.velcdn.com/images/eunzi_code/post/70c85dcf-0500-46b6-bf10-e725e53188c9/image.png" alt=""></p>
<pre><code class="language-java">import java.util.*;

public class Main {

    static int N,r,c,cnt=0;

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        r = sc.nextInt();
        c = sc.nextInt();

        find(r,c,(int)Math.pow(2, N));
        System.out.println(cnt);


    }

    static void find(int x,int y, int size) {
        if(size==1)
            return;

        if(x&lt;size/2&amp;&amp;y&lt;size/2) {    //왼쪽 위
            find(x,y,size/2);
        }else if(x&lt;size/2&amp;&amp;size/2&lt;=y) {    //오른쪽 위
            cnt+=(size*size/4);
            find(x,y-size/2,size/2);
        }else if(x&gt;=size/2&amp;&amp;size/2&gt;y) { //왼쪽 아래
            cnt+=(size*size/4)*2;
            find(x-size/2,y,size/2);
        }else {                        //오른쪽 아래
            cnt+=(size*size/4)*3;
            find(x-size/2,y-size/2,size/2);

        }

    }

}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 14940번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-14940%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-14940%EB%B2%88Java</guid>
            <pubDate>Thu, 29 May 2025 06:12:48 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/672948b8-1385-44de-8d15-fe3955156b32/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {
    static int[][] graph;
    static boolean[][] visited;
    static int[][] result;
    static int n, m;
    static int[] dx = {-1, 1, 0, 0};
    static int[] dy = {0, 0, -1, 1};
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(br.readLine(), &quot; &quot;);

        n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());

        graph = new int[n][m];
        visited = new boolean[n][m];
        result = new int[n][m];
        int x=0, y=0;

        for (int i = 0; i &lt; n; i++) {
            st = new StringTokenizer(br.readLine(), &quot; &quot;);
            for (int j = 0; j &lt; m; j++) {
                graph[i][j] = Integer.parseInt(st.nextToken());
                if (graph[i][j] == 2) {
                    x = i;
                    y = j;
                } else if (graph[i][j] == 0) {
                    visited[i][j] = true;
                }
            }
        }
        bfs(x, y);

        for (int i = 0; i &lt; n; i++) {
            for (int j = 0; j &lt; m; j++) {
                if (!visited[i][j]) {
                    result[i][j] = -1;
                }
                System.out.print(result[i][j] + &quot; &quot;);
            }
            System.out.println();
        }
    }

    public static void bfs(int x, int y) {
        Queue&lt;int[]&gt; queue = new LinkedList&lt;&gt;();
        queue.add(new int[]{x, y});
        visited[x][y] = true;

        while (!queue.isEmpty()) {
            int tmp[] = queue.poll();
            for (int i = 0; i &lt; 4; i++) {
                int nx = tmp[0] + dx[i];
                int ny = tmp[1] + dy[i];
                if (nx &gt;= 0 &amp;&amp; nx &lt; n &amp;&amp; ny &gt;= 0 &amp;&amp; ny &lt; m) {
                    if (!visited[nx][ny] &amp;&amp; graph[nx][ny] == 1) {
                        visited[nx][ny] = true;
                        result[nx][ny] = result[tmp[0]][tmp[1]] + 1;
                        queue.add(new int[]{nx, ny});
                    }
                }
            }
        }
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 11403번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-11403%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-11403%EB%B2%88Java</guid>
            <pubDate>Wed, 28 May 2025 01:24:57 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/783fb37c-4ba5-4e1c-88fe-60851f6b565a/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[][] map = new int[n][n];
        for (int i = 0; i &lt; n; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            for (int j = 0; j &lt; n; j++) {
                map[i][j] = Integer.parseInt(st.nextToken());
            }
        }

        // i에서 j까지 갈 수 있는가?
        // i에서 k로 가고, k에서 j로 갈 수 있는가?
        for (int k = 0; k &lt; n; k++) { // 거쳐갈 노드
            for (int i = 0; i &lt; n; i++) {
                for (int j = 0; j &lt; n; j++) {
                    // 단순히 갈 수 있는 경로가 있는지만 체크
                    if (map[i][k] == 1 &amp;&amp; map[k][j] == 1) {
                        map[i][j] = 1;
                    }
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i &lt; n; i++) {
            for (int j = 0; j &lt; n; j++) {
                sb.append(map[i][j] + &quot; &quot;);
            }
            sb.append(&quot;\n&quot;);
        }
        System.out.println(sb);

    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 11286번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-11286%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-11286%EB%B2%88Java</guid>
            <pubDate>Tue, 27 May 2025 00:46:19 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/6a5d2fe6-cc59-4934-9f4d-146db69d687b/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        PriorityQueue&lt;Integer&gt; pq = new PriorityQueue&lt;Integer&gt;(new Comparator&lt;Integer&gt;() {
            @Override
            public int compare(Integer o1, Integer o2) {
                if(Math.abs(o1) &gt; Math.abs(o2)) {
                    return Math.abs(o1) - Math.abs(o2);
                }else if(Math.abs(o1) == Math.abs(o2)) {
                    return o1 - o2;
                }else {
                    return -1;
                }
            }
        });
        StringBuilder sb = new StringBuilder();

        for(int i = 0; i &lt; N; i++) {
            int x = Integer.parseInt(br.readLine());
            if(x == 0) {
                if(pq.isEmpty()) sb.append(&quot;0&quot;).append(&quot;\n&quot;);
                else sb.append(pq.poll()).append(&quot;\n&quot;);
            }else {
                pq.offer(x);
            }
        }
        System.out.println(sb);
    }

}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 6064번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-6064%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-6064%EB%B2%88Java</guid>
            <pubDate>Mon, 26 May 2025 02:08:37 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/ccc58e36-5589-4056-994a-9449fec02bc6/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        int T = Integer.parseInt(br.readLine());

        for(int t=0; t&lt;T; t++) {
            StringTokenizer st = new StringTokenizer(br.readLine());

            int M = Integer.parseInt(st.nextToken());
            int N = Integer.parseInt(st.nextToken());
            int x = Integer.parseInt(st.nextToken());
            int y = Integer.parseInt(st.nextToken());

            // 최소공배수를 구하기 위해 최대공약수 구하기
            int a = N;
            int b = M;
            int tmp = 0;
            while (b != 0) {
                tmp = b;
                b = a % b;
                a = tmp;
            }

            // 최소공배수
            int lcm = M * N / a;
            int answer = -1;

            // 나머지가 0인 경우를 대비해 나머지가 x-1, y-1인 경우를 탐색
            // x-1 부터 시작해 M씩 더해가며 해답을 도출
            for (int i = x-1; i &lt; lcm + 1; i += M) {
                // (i%M) == x-1 이며(이미 충족), (i%N) == y-1인 i 탐색
                if (i % N == y-1) {
                    answer = i;
                    break;
                }
            }
            // 표현이 가능한 해면 + 1 해서 출력
            // 아니면 -1 출력
            sb.append(answer+1 !=0 ? answer+1 : -1).append(&#39;\n&#39;);
        }
        System.out.println(sb);

    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 5525번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-5525%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-5525%EB%B2%88Java</guid>
            <pubDate>Fri, 23 May 2025 02:00:59 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/80fdd3a4-66fe-4702-aadb-e4648a36e86f/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int m = Integer.parseInt(br.readLine());
        String str = br.readLine();
        int cnt=0, ans=0;

        for(int i=1; i&lt;m-1;){
            if(str.charAt(i)==&#39;O&#39; &amp;&amp; str.charAt(i+1)==&#39;I&#39;){
                cnt++;
                if(cnt == n){
                    if(str.charAt(i-(cnt*2-1))==&#39;I&#39;)
                        ans ++;
                    cnt--;
                }
                i+=2;
            }
            else {
                cnt=0;
                i++;
            }
        }
        System.out.println(ans);
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 2667번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-2667%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-2667%EB%B2%88Java</guid>
            <pubDate>Thu, 22 May 2025 13:03:15 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/7828703a-8a43-4e90-ac25-c566a8bb96ad/image.png" alt=""></p>
<pre><code class="language-java">import java.util.*;
import java.io.*;

public class Main {

    static int[][] danji;
    static boolean[][] visited;
    static int[] dx = {0,0,-1,1};
    static int[] dy = {-1,1,0,0};
    static List&lt;Integer&gt; result;
    static int cnt, N;

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        result = new LinkedList&lt;&gt;(); 
        N = Integer.parseInt(br.readLine());
        danji = new int[N][N];
        visited = new boolean[N][N]; //단지에 속해있는지
        cnt = 1; //기준이 아파트(단지로 묶일 첫 아파트)가 포함될 때니 1로 초기화

        for(int i=0;i&lt;N;i++) {
            String str = br.readLine();
            for(int j=0;j&lt;N;j++) {
                danji[i][j] = str.charAt(j)-&#39;0&#39;;
            }
        }


        for(int x=0;x&lt;N;x++) {
            for(int y=0;y&lt;N;y++) {
                if(danji[x][y]==1 &amp;&amp; !visited[x][y]) {
                    dfs(x,y);
                    result.add(cnt);
                    cnt = 1;
                }
            }
        }

        Collections.sort(result);

        bw.write(result.size()+&quot;\n&quot;);
        for(int r : result) bw.write(r+&quot;\n&quot;);
        bw.flush();
        bw.close();

    }

    public static void dfs(int x, int y) {
        visited[x][y] = true;

        for(int i=0;i&lt;4;i++) {
            int nx = dx[i]+x;
            int ny = dy[i]+y;

            if(nx&gt;=0 &amp;&amp; ny&gt;=0 &amp;&amp; nx&lt;N &amp;&amp; ny&lt;N &amp;&amp; !visited[nx][ny] &amp;&amp; danji[nx][ny]==1) {
                cnt++;
                dfs(nx,ny);
            }
        }
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 2178번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-2178%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-2178%EB%B2%88Java</guid>
            <pubDate>Wed, 14 May 2025 05:40:15 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/f59e4ac6-42fb-437e-ad2a-8f4fa8887d94/image.png" alt=""><img src="https://velog.velcdn.com/images/eunzi_code/post/cd9e8a0a-3132-4828-8f32-db689f8056c4/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {

    static int[][] map;
    static int n;
    static int m;
    static boolean[][] visited;
    static int[] dx = { -1, 1, 0, 0 }; //x방향배열-상하
    static int[] dy = { 0, 0, -1, 1 }; //y방향배열-좌우

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());

        map = new int[n][m];
        for(int i=0; i&lt;n; i++) {
            String s = br.readLine();
            for(int j=0; j&lt;m; j++) {
                map[i][j] = s.charAt(j) - &#39;0&#39;;
            }
        }

        visited = new boolean[n][m];
        visited[0][0] = true;
        bfs(0, 0);
        System.out.println(map[n-1][m-1]);
    }

    public static void bfs(int x, int y) {
        Queue&lt;int[]&gt; q = new LinkedList&lt;&gt;();
        q.add(new int[] {x,y});

        while(!q.isEmpty()) {
            int now[] = q.poll();
            int nowX = now[0];
            int nowY = now[1];

            for(int i=0; i&lt;4; i++) {
                int nextX = nowX + dx[i];
                int nextY = nowY + dy[i];

                        if (nextX &lt; 0 || nextY &lt; 0 || nextX &gt;= n || nextY &gt;= m)
                            continue;
                        if (visited[nextX][nextY] || map[nextX][nextY] == 0)
                            continue;

                        q.add(new int[] {nextX, nextY});
                        map[nextX][nextY] = map[nowX][nowY] + 1;
                        visited[nextX][nextY] = true;
            }
        }
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 1697번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-1697%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-1697%EB%B2%88Java</guid>
            <pubDate>Mon, 12 May 2025 02:42:50 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/621a449f-5421-48bc-8138-65cc98399f7f/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main
{
    static int N;
    static int K;

    static int visited[] = new int[100001];

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String input = br.readLine();
        String[] inputs = input.split(&quot; &quot;);

        N = Integer.valueOf(inputs[0]);
        K = Integer.valueOf(inputs[1]);

        int result = bfs(N);
        System.out.println(result);
    }

    private static int  bfs(int node)
    {
        Queue&lt;Integer&gt; queue = new LinkedList&lt;Integer&gt;();

        queue.add(node);
        int index = node;
        int n = 0;
        visited[index] = 1;
        while (queue.isEmpty() == false)
        {
            n = queue.remove();

            if (n == K)
            {
                return visited[n]-1;
            }

            if (n-1&gt;=0 &amp;&amp; visited[n-1] == 0)
            {
                visited[n-1] = visited[n]+1;
                queue.add(n-1);
            }
            if (n+1 &lt;= 100000 &amp;&amp; visited[n+1] == 0)
            {
                visited[n+1] = visited[n]+1;
                queue.add(n+1);
            }
            if (2*n &lt;= 100000 &amp;&amp; visited[2*n] == 0)
            {
                visited[2*n] = visited[n] + 1;
                queue.add(2*n);
            }
        }
        return -1;
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 1389번(Java)]]></title>
            <link>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-1389%EB%B2%88Java</link>
            <guid>https://velog.io/@eunzi_code/%EB%B0%B1%EC%A4%80-1389%EB%B2%88Java</guid>
            <pubDate>Fri, 02 May 2025 02:55:15 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/eunzi_code/post/9fb9bc0e-29c1-4ec4-9396-181c36e22570/image.png" alt=""><img src="https://velog.velcdn.com/images/eunzi_code/post/31fd37c7-c34e-40c0-bdb6-80e79ff8ae2d/image.png" alt=""></p>
<pre><code class="language-java">import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());


        List&lt;List&lt;Integer&gt;&gt; graph = new ArrayList&lt;&gt;();
        for (int i = 0; i &lt; N + 1; i++) {
            graph.add(new ArrayList&lt;&gt;());
        }

        for (int i = 0; i &lt; M; i++) {
            st = new StringTokenizer(br.readLine());
            int u = Integer.parseInt(st.nextToken());
            int v = Integer.parseInt(st.nextToken());

            graph.get(u).add(v);
            graph.get(v).add(u);
        }

        int KB[] = new int[N + 1];
        for (int i = 1; i &lt; N + 1; i++) {
            Queue&lt;Integer&gt; queue = new LinkedList&lt;&gt;();
            queue.add(i);
            int[] distance = new int[N + 1];
            Arrays.fill(distance, -1);
            distance[i] = 0;
            while (!queue.isEmpty()) {
                int current = queue.poll();
                for (int next : graph.get(current)) {
                    if (distance[next] == -1) {
                        distance[next] = distance[current] + 1;
                        queue.add(next);
                    }
                }
            }
            int sum = 0;
            for (int j = 1; j &lt; N + 1; j++) {
                sum += distance[j];
            }
            KB[i] = sum;
        }

        int min = Integer.MAX_VALUE;
        int answer = 0;
        for (int i = 1; i &lt; N + 1; i++) {
            if (KB[i] &lt; min) {
                min = KB[i];
                answer = i;
            }
        }
        System.out.println(answer);
    }
}</code></pre>
]]></description>
        </item>
    </channel>
</rss>