This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |