#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
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 |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
760 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
5124 KB |
Output is correct |
2 |
Correct |
108 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3601 ms |
92788 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |