diff --git "a/lkhyun/202507/26 BOJ G4 \354\230\244\355\201\260\354\210\230.md" "b/lkhyun/202507/26 BOJ G4 \354\230\244\355\201\260\354\210\230.md" new file mode 100644 index 00000000..b41bfc75 --- /dev/null +++ "b/lkhyun/202507/26 BOJ G4 \354\230\244\355\201\260\354\210\230.md" @@ -0,0 +1,43 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int[] arr; + static int[] NGE; + + public static void main(String[] args) throws Exception { + int N = Integer.parseInt(br.readLine()); + arr = new int[N]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + if(N == 1){ + bw.write("-1"); + bw.close(); + return; + } + + NGE = new int[N]; + ArrayDeque stk = new ArrayDeque<>(); + stk.push(0); + for (int i = 1; i < N; i++) { + while(!stk.isEmpty() && arr[stk.peek()]