Submission #652824

# Submission time Handle Problem Language Result Execution time Memory
652824 2022-10-24T16:47:08 Z omkarbajaj073 Sightseeing (NOI14_sightseeing) C++17
15 / 25
3500 ms 192332 KB
#include <bits/stdc++.h>

using namespace std;


const int MAX_N = 5e5 + 10;

int n, m, q;
vector<pair<int, int> > graph[MAX_N];
int dist[MAX_N];

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> m >> q;

  for (int i = 0; i < m; i++) {
    int a, b, w; cin >> a >> b >> w;
    graph[a].push_back({b, w});
    graph[b].push_back({a, w});
  }

  dist[1] = INT_MAX;
  for (int i = 2; i <= n; i++) {
    dist[i] = 0;
  }

  priority_queue<pair<int, int> > pq;

  pq.push({dist[1], 1});
  while(!pq.empty()) {
    auto [d, u] = pq.top(); pq.pop();
    if (d < dist[u]) continue;
    for (auto [v, w]: graph[u]) {
      int weight = min(w, d);
      if (weight > dist[v]) {
        dist[v] = weight;
        pq.push({dist[v], v});
      }
    }
  }

  while (q--) {
    int query; cin >> query;
    cout << dist[query] << endl;
  }



  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12116 KB Output is correct
2 Correct 8 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 14176 KB Output is correct
2 Correct 43 ms 13788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2438 ms 106804 KB Output is correct
2 Execution timed out 3583 ms 192332 KB Time limit exceeded
3 Halted 0 ms 0 KB -