SHARE
TWEET

Untitled

a guest May 15th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. // 定義陣列最大尺寸
  6. #define AMAX (int)(1e5 + 7)
  7.  
  8. int main()
  9. {
  10.     int N, M, K, U[AMAX], V[AMAX], L[AMAX], mini = 2e9;
  11.     bool s[AMAX];
  12.  
  13.     // 輸入
  14.     cin >> N >> M >> K;
  15.     fill(s, s + N, false);
  16.    
  17.     for(int i = 0; i < M; ++i)
  18.     {
  19.         cin >> U[i] >> V[i] >> L[i];
  20.     }
  21.     for(int i = 0; i < K; ++i)
  22.     {
  23.         int t;
  24.         cin >> t;
  25.         // 紀錄有倉庫的城市
  26.         s[t] = true;
  27.     }
  28.    
  29.     // 查找每一條道路
  30.     for(int i = 0; i < M; ++i)
  31.     {
  32.         // 假如兩端一個有倉庫一個沒有,而且比較短,就記起來
  33.         if((s[U[i]] ^ s[V[i]]) && L[i] < mini)
  34.         {
  35.             mini = L[i];
  36.         }
  37.     }
  38.  
  39.     // 至少有找到一條就輸出最短的,不然輸出-1
  40.     cout << (mini == 2e9 ? -1 : mini) << endl;
  41.  
  42.     return 0;
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top