@@ -18,13 +18,13 @@ public int compareTo(Node o) {
18
18
19
19
List <ArrayList <Node >> graph = new ArrayList <>();
20
20
int [] table ;
21
- Set <Integer > summitSet = new HashSet <>();
21
+ List <Integer > summitSet = new ArrayList <>();
22
22
public int [] solution (int n , int [][] paths , int [] gates , int [] summits ) {
23
- //산봉우리 중복제거
23
+ //산봉우리 확인용
24
24
for (int mountain : summits ){
25
25
summitSet .add (mountain );
26
26
}
27
- //최소 가중치 테이블 초기화
27
+ //최소 intensity 테이블 초기화
28
28
table = new int [n +1 ];
29
29
Arrays .fill (table , Integer .MAX_VALUE );
30
30
//그래프 모델링
@@ -44,7 +44,7 @@ public int[] solution(int n, int[][] paths, int[] gates, int[] summits) {
44
44
int [] answer = {0 ,Integer .MAX_VALUE };
45
45
for (int mountain : summits ) {
46
46
int intensity = answer [1 ];
47
- if (table [mountain ] < intensity ) { //intensity의 최솟값
47
+ if (table [mountain ] < intensity ) { //최소 intensity 구하기
48
48
answer [0 ] = mountain ;
49
49
answer [1 ] = table [mountain ];
50
50
} else if (table [mountain ] == intensity && mountain < answer [0 ]) {
@@ -54,8 +54,7 @@ public int[] solution(int n, int[][] paths, int[] gates, int[] summits) {
54
54
return answer ;
55
55
}
56
56
57
- // 휴식 없이 이동해야 하는 시간 중 가장 긴 시간을 해당 등산코스의 intensity (가중치)
58
- // 출입구는 처음과 끝에 한 번씩, 산봉우리는 한 번만 포함 -> 출발 > 산봉우리 까지의 거리
57
+ // 출입구는 처음과 끝에 한 번씩, 산봉우리는 한 번만 포함 -> 출발 > 산봉우리 까지의 단방향 거리만 구하면됨
59
58
void dijkstra (int [] gates ){
60
59
PriorityQueue <Node > pq = new PriorityQueue <>();
61
60
//출발지점으로 초기화
@@ -78,8 +77,8 @@ void dijkstra(int[] gates){
78
77
79
78
for (Node next : graph .get (index )){
80
79
int nextIndex = next .index ;
81
- int cost = Math .max (table [index ], next .distance );
82
- if (table [nextIndex ] > cost ){
80
+ int cost = Math .max (table [index ], next .distance );//현재 지점에서 다음 지점으로 갈 때 가장 긴 등산코스(intensity)를 찾기
81
+ if (table [nextIndex ] > cost ){//그 중 최소 intensity 찾기
83
82
table [nextIndex ] = cost ;
84
83
pq .offer (new Node (nextIndex , cost ));
85
84
}
0 commit comments