2025/06/11 5

[백준] 16437번. 양 구출 작전(JAVA)

문제https://www.acmicpc.net/problem/16437플이(32분)import java.io.*;import java.util.*;public class Main { static List[] tree; // 트리 구조 표현 (인접 리스트) static long[] animalCount; // 각 노드에 있는 양 또는 늑대 수 (양: 양수, 늑대: 음수) public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int nodeCount = Integer.parseI..

[백준]16964번. DFS 스페셜 저지(JAVA)

문제https://www.acmicpc.net/problem/16964풀이(30분)import java.io.*;import java.util.*;public class Main { // 인접 리스트 (그래프) static List> list = new ArrayList(); static boolean[] visited; // 방문 여부 static int[] next; // 주어진 방문 순서 static boolean flag; // 순서가 유효한지 판별 static int n, idx; // 정점 수, 현재 순서 인덱스 public static void main(String[] args) throws NumberFormatExce..