Skip to content

Commit 15e81bb

Browse files
committed
[Silver II] Title: 알고리즘 수업 - 깊이 우선 탐색 2, Time: 784 ms, Memory: 86592 KB -BaekjoonHub
1 parent 7b8ba0b commit 15e81bb

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

백준/Silver/24480. 알고리즘 수업 - 깊이 우선 탐색 2/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 105216 KB, 시간: 852 ms
7+
메모리: 86592 KB, 시간: 784 ms
88

99
### 분류
1010

1111
그래프 이론, 그래프 탐색, 정렬, 깊이 우선 탐색
1212

1313
### 제출 일자
1414

15-
2025년 8월 8일 17:50:52
15+
2025년 8월 8일 17:58:32
1616

1717
### 문제 설명
1818

백준/Silver/24480. 알고리즘 수업 - 깊이 우선 탐색 2/알고리즘 수업 - 깊이 우선 탐색 2.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import java.util.*;
33

44
public class Main {
5-
static List<List<Integer>> graph = new ArrayList<>();
5+
static List<PriorityQueue<Integer>> graph = new ArrayList<>();
66
static boolean[] visited;
77
static int N, M, R, count=1;
88
static int[] result;
@@ -19,7 +19,7 @@ public static void main(String[] args) throws IOException{
1919
result = new int[N+1];
2020

2121
for(int i=0; i<=N; i++){
22-
graph.add(new ArrayList<>());
22+
graph.add(new PriorityQueue<>(Collections.reverseOrder()));
2323
}
2424

2525
for(int i=1; i<=M; i++){
@@ -44,12 +44,19 @@ public static void main(String[] args) throws IOException{
4444
public static void dfs(int curr){
4545
visited[curr] = true;
4646
result[curr] = count++;
47-
Collections.sort(graph.get(curr), Collections.reverseOrder()); //역순 재정렬
48-
49-
for(int next :graph.get(curr)){
50-
if(!visited[next]){
47+
// Collections.sort(graph.get(curr), Collections.reverseOrder()); //역순 재정렬
48+
PriorityQueue<Integer> pq = graph.get(curr);
49+
while (!pq.isEmpty()) {
50+
int next = pq.poll();
51+
if (!visited[next]) {
5152
dfs(next);
5253
}
5354
}
55+
56+
// for(int next :graph.get(curr)){
57+
// if(!visited[next]){
58+
// dfs(next);
59+
// }
60+
// }
5461
}
5562
}

0 commit comments

Comments
 (0)