File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed
백준/Silver/24480. 알고리즘 수업 - 깊이 우선 탐색 2 Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 22import java .util .*;
33
44public 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}
You can’t perform that action at this time.
0 commit comments