Skip to content

Commit 1664265

Browse files
authored
[20250407] BOJ / G2 / 면접보는 승범이네 / 권혁준
1 parent 3de2b82 commit 1664265

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st = new StringTokenizer("");
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static String nextToken() throws Exception {
15+
while(!st.hasMoreTokens()) nextLine();
16+
return st.nextToken();
17+
}
18+
static int nextInt() throws Exception { return Integer.parseInt(nextToken()); }
19+
static long nextLong() throws Exception { return Long.parseLong(nextToken()); }
20+
static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
21+
static void bwEnd() throws Exception {bw.flush();bw.close();}
22+
23+
// Additional field
24+
25+
static int N, M, K;
26+
static List<int[]>[] V;
27+
28+
static final long INF = (long)1e18 + 7;
29+
30+
public static void main(String[] args) throws Exception {
31+
32+
ready();
33+
solve();
34+
35+
bwEnd();
36+
37+
}
38+
39+
static void ready() throws Exception{
40+
41+
N = nextInt();
42+
M = nextInt();
43+
K = nextInt();
44+
V = new List[N+1];
45+
for(int i=1;i<=N;i++) V[i] = new ArrayList<>();
46+
for(int i=0;i<M;i++) {
47+
int a = nextInt(), b = nextInt(), c = nextInt();
48+
V[b].add(new int[] {a,c});
49+
}
50+
51+
}
52+
53+
static void solve() throws Exception{
54+
55+
PriorityQueue<long[]> Q = new PriorityQueue<>((a,b) -> {
56+
if(a[0] < b[0]) return -1;
57+
if(a[0] > b[0]) return 1;
58+
return 0;
59+
});
60+
long[] D = new long[N+1];
61+
Arrays.fill(D, INF);
62+
for(int i=0;i<K;i++) {
63+
int k = nextInt();
64+
D[k] = 0;
65+
Q.offer(new long[] {0,k});
66+
}
67+
68+
while(!Q.isEmpty()) {
69+
long[] now = Q.poll();
70+
long d = now[0];
71+
int n = (int)now[1];
72+
if(d > D[n]) continue;
73+
for(int[] next:V[n]) {
74+
int i = next[0], c = next[1];
75+
if(D[i] > d+c) {
76+
D[i] = d+c;
77+
Q.offer(new long[] {D[i],i});
78+
}
79+
}
80+
}
81+
82+
long num = -1, dist = -1;
83+
for(int i=1;i<=N;i++) if(D[i] != INF) {
84+
if(D[i] > dist) {
85+
num = i;
86+
dist = D[i];
87+
}
88+
}
89+
bw.write(num + "\n" + dist);
90+
91+
}
92+
93+
}
94+
95+
```

0 commit comments

Comments
 (0)