-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudy_1916.java
More file actions
53 lines (44 loc) · 1011 Bytes
/
Study_1916.java
File metadata and controls
53 lines (44 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.PriorityQueue;
import java.util.Scanner;
// Create by Inho 2018. 5. 2.
public class Study_1916 {
public static void main(String[] args){
int INF = 1000000001;
Scanner sc = new Scanner(System.in);
int N = sc.nextInt()+1;
int M = sc.nextInt();
int[] d = new int[N];
int[][] map = new int[N][N];
for(int i=0;i<N;i++){
d[i] = INF;
for(int j=0;j<N;j++){
map[i][j] = INF;
if(i==j){
map[i][j] =0;
}
}
}
for(int i=0;i<M;i++){
int first = sc.nextInt();
int second = sc.nextInt();
int value = sc.nextInt();
if(map[first][second] > value)
map[first][second]=value;
}
int start = sc.nextInt();
int end = sc.nextInt();
PriorityQueue<Integer> q = new PriorityQueue<>();
q.offer(start);
d[start] =0;
while(!q.isEmpty()){
int node = q.poll();
for(int i=1;i<N;i++){
if(d[i] > map[node][i] + d[node]){
d[i] = map[node][i] + d[node];
q.offer(i);
}
}
}
System.out.println(d[end]);
}
}