Submission #652824

#TimeUsernameProblemLanguageResultExecution timeMemory
652824omkarbajaj073Sightseeing (NOI14_sightseeing)C++17
15 / 25
3583 ms192332 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...