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;
#define int long long
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int v, e, q;
cin >> v >> e >> q;
vector<vector<pair<int, int>>> graph(v+1);
for (int i = 0; i < e; i++) {
int a, b, qual;
cin >> a >> b >> qual;
graph[a].emplace_back(qual, b);
graph[b].emplace_back(qual, a);
}
priority_queue<pair<int, int>> queue;
queue.push(make_pair(1000000, 1));
vector<bool> visited(v + 1);
vector<int> optimum(v + 1);
while (!queue.empty()) {
pair<int, int> pos = queue.top();
queue.pop();
if (visited[pos.second]) continue;
visited[pos.second] = true;
optimum[pos.second] = pos.first;
for (pair<int, int> adj : graph[pos.second]) {
queue.push(make_pair(min(pos.first, adj.first), adj.second));
}
}
for (int i = 0; i < q; i++) {
int query;
cin >> query;
cout << optimum[query] << "\n";
}
}
# | 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... |