#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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
760 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
5748 KB |
Output is correct |
2 |
Correct |
50 ms |
4736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3330 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |