Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions SeJunAn/1260.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import java.util.*;

// 커밋 메시지 변경
public class Main {
static int N, M, V;
static List<Integer>[] 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<Integer> 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);
}
}
}
}
}
41 changes: 41 additions & 0 deletions SeJunAn/14501.java
Original file line number Diff line number Diff line change
@@ -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();
}
}