From ecb2389bac0d087c4d140498c1714ecf6b1b93e4 Mon Sep 17 00:00:00 2001 From: SeJunAn Date: Sun, 16 Feb 2025 23:36:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[1260=20-=20solve]=20DFS=EC=99=80=20BFS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SeJunAn/1260.java | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 SeJunAn/1260.java diff --git a/SeJunAn/1260.java b/SeJunAn/1260.java new file mode 100644 index 0000000..12550ad --- /dev/null +++ b/SeJunAn/1260.java @@ -0,0 +1,68 @@ +import java.util.*; + +// 커밋 메시지 변경 +public class Main { + static int N, M, V; + static List[] adj; + static boolean[] vis; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + N = sc.nextInt(); + M = sc.nextInt(); + V = sc.nextInt(); + + adj = new ArrayList[N + 1]; + for (int i = 1; i <= N; i++) { + adj[i] = new ArrayList<>(); + } + + for (int i = 0; i < M; i++) { + int u = sc.nextInt(); + int v = sc.nextInt(); + adj[u].add(v); + adj[v].add(u); + } + + for (int i = 1; i <= N; i++) { + Collections.sort(adj[i]); + } + + vis = new boolean[N + 1]; + DFS(V); + System.out.println(); + + vis = new boolean[N + 1]; + BFS(V); + } + + public static void DFS(int cur) { + System.out.print(cur + " "); + vis[cur] = true; + + for (int nxt : adj[cur]) { + if (!vis[nxt]) { + DFS(nxt); + } + } + } + + public static void BFS(int start) { + Queue q = new LinkedList<>(); + q.add(start); + vis[start] = true; + + while (!q.isEmpty()) { + int cur = q.poll(); + System.out.print(cur + " "); + + for (int nxt : adj[cur]) { + if (!vis[nxt]) { + vis[nxt] = true; + q.add(nxt); + } + } + } + } +} From e16aa7b9b46bfa7a33a07f885e8e72e359e2669b Mon Sep 17 00:00:00 2001 From: SeJunAn Date: Sun, 16 Feb 2025 23:37:18 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[14501=20-=20fail]=20=ED=87=B4=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SeJunAn/14501.java | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 SeJunAn/14501.java diff --git a/SeJunAn/14501.java b/SeJunAn/14501.java new file mode 100644 index 0000000..2ea585b --- /dev/null +++ b/SeJunAn/14501.java @@ -0,0 +1,41 @@ +import java.io.*; + +// 커밋메시지 변경 +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + // 퇴사일 + int quit_day = Integer.parseInt(br.readLine()); + + // 시간과 급여 배열 + int[] time = new int[quit_day + 1]; + int[] wage = new int[quit_day + 1]; + int[] dp = new int[quit_day + 2]; // dp 배열 (퇴사일까지 얻을 수 있는 최대 급여) + + // 입력 처리 + for (int i = 1; i <= quit_day; i++) { + String[] input = br.readLine().split(" "); + time[i] = Integer.parseInt(input[0]); + wage[i] = Integer.parseInt(input[1]); + } + + // 역순으로 계산 (퇴사일 이전부터 시작) + for (int i = quit_day; i >= 1; i--) { + // 일을 끝낼 수 있는 날이 퇴사일을 넘지 않으면, 해당 일을 할 수 있음 + if (i + time[i] <= quit_day + 1) { + dp[i] = Math.max(dp[i + 1], wage[i] + dp[i + time[i]]); + } else { + dp[i] = dp[i + 1]; // 일을 할 수 없으면 그 날의 최대 급여는 그대로 + } + } + + // 첫 번째 날부터 시작할 때 얻을 수 있는 최대 급여가 정답 + bw.write(dp[1] + "\n"); + + br.close(); + bw.flush(); + bw.close(); + } +} \ No newline at end of file