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. cout << n << m << k;
  11. for (int i = 0; i < m; i++) {
  12. int u, v, w;
  13. cin >> u >> v >> w;
  14. u--;
  15. v--;
  16. adj[u].push_back({v, w});
  17. adj[v].push_back({u, w});
  18. }
  19. unordered_set<int> storages;
  20. for (int i = 0; i < k; i++) {
  21. int x;
  22. cin >> x;
  23. x--;
  24. storages.insert(x);
  25. }
  26. int ans = 2e9;
  27. for (auto it = storages.begin(); it != storages.end(); it++) {
  28. for (pair<int, int>& v : adj[*it]) {
  29. if (storages.find(v.first) == storages.end()) {
  30. ans = min(ans, v.second);
  31. }
  32. }
  33. }
  34. if (ans == 2e9) cout << -1 << endl;
  35. else cout << ans << endl;
  36. }
  37.  
  38. int main() {
  39. solve();
  40. }
Success #stdin #stdout 0.01s 5264KB
stdin
5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5
stdout
5423