#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
int v, e, q, a, b, w, maxi[500001];
vector<pi> adjlist[500001];
priority_queue<pi> pq;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(maxi, -1, sizeof(maxi));
cin >> v >> e >> q;
for(int i = 0; i < e; i++){
cin >> a >> b >> w;
adjlist[a].push_back(pi(b, w));
adjlist[b].push_back(pi(a, w));
}
maxi[1] = INT_MAX;
pq.push(pi(INT_MAX, 1));
while(!pq.empty()){
pi f = pq.top(); pq.pop();
for(vector<pi>::iterator it = adjlist[f.second].begin(); it != adjlist[f.second].end(); it++){
if(maxi[(*it).first] < min(f.first, (*it).second)){
maxi[(*it).first] = min(f.first, (*it).second);
pq.push(pi(maxi[(*it).first], (*it).first));
}
}
}
for(int i = 0; i < q; i++){
cin >> a;
cout << maxi[a] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
14200 KB |
Output is correct |
2 |
Correct |
14 ms |
14072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
14328 KB |
Output is correct |
2 |
Correct |
14 ms |
14072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
17016 KB |
Output is correct |
2 |
Correct |
47 ms |
16444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3406 ms |
164676 KB |
Output is correct |
2 |
Execution timed out |
3606 ms |
218580 KB |
Time limit exceeded |