#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector< vector< pair<int, int> > > Graph(n+1);
for(int i = 0; i < m; i++){
int a, b, c;
cin >> a >> b >> c;
Graph[a].push_back(make_pair(b,c));
Graph[b].push_back(make_pair(a,c));
}
vector< int > dist(n+1, -INF);
priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq;
dist[1] = INF;
pq.push(make_pair(INF,1));
while(!pq.empty()){
pair<int, int> pair = pq.top();
pq.pop();
int node = pair.second;
int cost = pair.first;
if(cost < dist[node]) continue;
for(int i = 0; i < (int)Graph[node].size(); i++){
int to = Graph[node][i].first;
int price = Graph[node][i].second;
if(min(cost, price) > dist[to]){
dist[to] = min(cost, price);
pq.push(make_pair(dist[to], to));
}
}
}
for(int i = 0; i < q; i++){
int a;
cin >> a;
cout << dist[a] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
508 KB |
Output is correct |
2 |
Correct |
9 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3528 ms |
3192 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3533 ms |
98624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |