From d53e46db048395dc8db26f861e55811f73cc4959 Mon Sep 17 00:00:00 2001 From: sunha20 Date: Tue, 20 Jan 2026 11:07:32 +0900 Subject: [PATCH 1/2] =?UTF-8?q?add:=20BOJ22856=5F=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EC=88=9C=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\246\254\354\210\234\355\232\214.java" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "_sunha/BOJ22856_\355\212\270\353\246\254\354\210\234\355\232\214.java" diff --git "a/_sunha/BOJ22856_\355\212\270\353\246\254\354\210\234\355\232\214.java" "b/_sunha/BOJ22856_\355\212\270\353\246\254\354\210\234\355\232\214.java" new file mode 100644 index 00000000..caf022cc --- /dev/null +++ "b/_sunha/BOJ22856_\355\212\270\353\246\254\354\210\234\355\232\214.java" @@ -0,0 +1,70 @@ +/** BOJBOJ22856_트리순회 + * # 문제 + * - + * + * # 제한 + * + * + * # 풀이 + * + * + */ + +import java.io.*; + +public class BOJ22856_트리순회 { + + static class Node { + int left, right; + + void set(int left, int right) { + this.left = left; + this.right = right; + } + } + + static int N, cnt, endNode; + static Node[] tree; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + String[] temp; + tree = new Node[N+1]; + int now; + for (int n=0; n 0) { + travel(tree[now].left); + cnt++; + } + + if (now == endNode) { + System.out.println(cnt - 1); // 시작점 카운트(1) 제외하고 출력 + } + + if (tree[now].right > 0) { + travel(tree[now].right); + cnt++; + } + + } +} From 09b451de9a960a87b4bdaad73bb843a2bed34686 Mon Sep 17 00:00:00 2001 From: sunha20 Date: Wed, 28 Jan 2026 08:46:05 +0900 Subject: [PATCH 2/2] =?UTF-8?q?add:=20endNode=20=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\212\270\353\246\254\354\210\234\355\232\214.java" | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git "a/_sunha/BOJ22856_\355\212\270\353\246\254\354\210\234\355\232\214.java" "b/_sunha/BOJ22856_\355\212\270\353\246\254\354\210\234\355\232\214.java" index caf022cc..5517220f 100644 --- "a/_sunha/BOJ22856_\355\212\270\353\246\254\354\210\234\355\232\214.java" +++ "b/_sunha/BOJ22856_\355\212\270\353\246\254\354\210\234\355\232\214.java" @@ -57,14 +57,14 @@ static void travel(int now) { cnt++; } - if (now == endNode) { - System.out.println(cnt - 1); // 시작점 카운트(1) 제외하고 출력 - } - if (tree[now].right > 0) { travel(tree[now].right); cnt++; } + if (now == endNode) { + System.out.println(cnt - 1); // 시작점 카운트(1) 제외하고 출력 + } + } }