fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 2e5 + 5;
  5.  
  6. void solve() {
  7. int n, m, k;
  8. cin >> n >> m >> k;
  9. vector<vector<pair<int, int>>> adj(n);
  10. for (int i = 0; i < m; i++) {
  11. int u, v, w;
  12. cin >> u >> v >> w;
  13. u--;
  14. v--;
  15. adj[u].push_back({v, w});
  16. adj[v].push_back({u, w});
  17. }
  18. unordered_set<int> storages;
  19. for (int i = 0; i < k; i++) {
  20. int x;
  21. cin >> x;
  22. x--;
  23. storages.insert(x);
  24. }
  25. int ans = 2e9;
  26. for (auto it = storages.begin(); it != storages.end(); it++) {
  27. for (pair<int, int>& v : adj[*it]) {
  28. if (storages.find(v.first) == storages.end()) {
  29. ans = min(ans, v.second);
  30. }
  31. }
  32. }
  33. if (ans == 2e9) cout << -1 << endl;
  34. else cout << ans << endl;
  35. }
  36.  
  37. int main() {
  38. solve();
  39. }
Success #stdin #stdout 0.01s 5288KB
stdin
3 1 1
1 2 3
3
stdout
-1