|
| 1 | +```java |
| 2 | +import java.util.*; |
| 3 | +import java.io.*; |
| 4 | + |
| 5 | +class IOController { |
| 6 | + BufferedReader br; |
| 7 | + BufferedWriter bw; |
| 8 | + StringTokenizer st; |
| 9 | + |
| 10 | + public IOController() { |
| 11 | + br = new BufferedReader(new InputStreamReader(System.in)); |
| 12 | + bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 13 | + st = new StringTokenizer(""); |
| 14 | + } |
| 15 | + |
| 16 | + String nextLine() throws Exception { |
| 17 | + String line = br.readLine(); |
| 18 | + st = new StringTokenizer(line); |
| 19 | + return line; |
| 20 | + } |
| 21 | + |
| 22 | + String nextToken() throws Exception { |
| 23 | + while (!st.hasMoreTokens()) nextLine(); |
| 24 | + return st.nextToken(); |
| 25 | + } |
| 26 | + |
| 27 | + int nextInt() throws Exception { |
| 28 | + return Integer.parseInt(nextToken()); |
| 29 | + } |
| 30 | + |
| 31 | + long nextLong() throws Exception { |
| 32 | + return Long.parseLong(nextToken()); |
| 33 | + } |
| 34 | + |
| 35 | + double nextDouble() throws Exception { |
| 36 | + return Double.parseDouble(nextToken()); |
| 37 | + } |
| 38 | + |
| 39 | + void close() throws Exception { |
| 40 | + bw.flush(); |
| 41 | + bw.close(); |
| 42 | + } |
| 43 | + |
| 44 | + void write(String content) throws Exception { |
| 45 | + bw.write(content); |
| 46 | + } |
| 47 | + |
| 48 | +} |
| 49 | + |
| 50 | +public class Main { |
| 51 | + |
| 52 | + static IOController io; |
| 53 | + |
| 54 | + // |
| 55 | + |
| 56 | + static int N, M, K; |
| 57 | + static List<int[]>[] V; |
| 58 | + |
| 59 | + public static void main(String[] args) throws Exception { |
| 60 | + |
| 61 | + io = new IOController(); |
| 62 | + |
| 63 | + init(); |
| 64 | + solve(); |
| 65 | + |
| 66 | + io.close(); |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + public static void init() throws Exception { |
| 71 | + |
| 72 | + N = io.nextInt(); |
| 73 | + M = io.nextInt(); |
| 74 | + K = io.nextInt(); |
| 75 | + V = new List[N+1]; |
| 76 | + for(int i=1;i<=N;i++) V[i] = new ArrayList<>(); |
| 77 | + for(int i=0;i<M;i++) { |
| 78 | + int a = io.nextInt(), b = io.nextInt(), c = io.nextInt(); |
| 79 | + V[a].add(new int[]{b,c}); |
| 80 | + V[b].add(new int[]{a,c}); |
| 81 | + } |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + static void solve() throws Exception { |
| 86 | + |
| 87 | + int[] D = new int[N+1]; |
| 88 | + Arrays.fill(D, (int)1e9); |
| 89 | + PriorityQueue<int[]> Q = new PriorityQueue<>((a,b) -> a[0]-b[0]); |
| 90 | + for(int i=0;i<K;i++) { |
| 91 | + int a = io.nextInt(); |
| 92 | + D[a] = 0; |
| 93 | + Q.offer(new int[]{0,a}); |
| 94 | + } |
| 95 | + |
| 96 | + while(!Q.isEmpty()) { |
| 97 | + int[] now = Q.poll(); |
| 98 | + int d = now[0], n = now[1]; |
| 99 | + if(d > D[n]) continue; |
| 100 | + for(int[] e:V[n]) { |
| 101 | + int i = e[0], c = e[1]; |
| 102 | + if(D[i] > d+c) { |
| 103 | + D[i] = d+c; |
| 104 | + Q.offer(new int[]{D[i],i}); |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + int ans = 0; |
| 110 | + for(int n=1;n<=N;n++) for(int[] e:V[n]) { |
| 111 | + int i = e[0], c = e[1]; |
| 112 | + if(D[n] + c == D[i]) continue; |
| 113 | + ans = Math.max(Math.max(ans, D[n]*2), Math.max(D[i]*2, (D[n]+D[i]+c))); |
| 114 | + } |
| 115 | + |
| 116 | + io.write((ans+1)/2 + "\n"); |
| 117 | + |
| 118 | + } |
| 119 | + |
| 120 | +} |
| 121 | +``` |
0 commit comments