From 2f8211541d4e0efdf67d215d134722f4bd9e45ab Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 19 Mar 2025 13:28:45 +0900 Subject: [PATCH] =?UTF-8?q?[20250319]=20BOJ=20/=20G3=20/=20=EC=9D=8C?= =?UTF-8?q?=EC=95=85=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=A8=20/=20=EA=B9=80?= =?UTF-8?q?=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\353\241\234\352\267\270\353\236\250.md" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "suyeun84/202503/19 BOJ G3 \354\235\214\354\225\205\355\224\204\353\241\234\352\267\270\353\236\250.md" diff --git "a/suyeun84/202503/19 BOJ G3 \354\235\214\354\225\205\355\224\204\353\241\234\352\267\270\353\236\250.md" "b/suyeun84/202503/19 BOJ G3 \354\235\214\354\225\205\355\224\204\353\241\234\352\267\270\353\236\250.md" new file mode 100644 index 00000000..fd3613a2 --- /dev/null +++ "b/suyeun84/202503/19 BOJ G3 \354\235\214\354\225\205\355\224\204\353\241\234\352\267\270\353\236\250.md" @@ -0,0 +1,54 @@ +```java +import java.io.*; +import java.util.*; + +public class boj2623 { + 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());} + + public static void main(String[] args) throws Exception { + nextLine(); + int N = nextInt(); + int M = nextInt(); + int[] cnt = new int[N+1]; + ArrayList answer = new ArrayList<>(); + ArrayList> graph = new ArrayList<>(); + for (int i = 0; i < N+1; i++) graph.add(new ArrayList<>()); + + for (int i = 0; i < M; i++) { + nextLine(); + int num = nextInt(); + int prev = nextInt(); + for (int j = 0; j < num-1; j++) { + int curr = nextInt(); + graph.get(prev).add(curr); + cnt[curr]++; + prev = curr; + } + } + while (answer.size() != N) { + boolean flag = true; + for (int i = 1; i < N+1; i++) { + if (cnt[i] == 0) { + cnt[i] = -1; + answer.add(i); + for (int next : graph.get(i)) { + cnt[next]--; + } + flag = false; + } + } + if (flag) { + System.out.println(0); + return; + } + } + for (int i = 0; i < N; i++) { + System.out.println(answer.get(i)); + } + } +} + +```