#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int v, e, q; cin >> v >> e >> q;
vector<pair<int, int> > adj[v + 1];
while(e--){
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({w, v});
adj[v].push_back({w, u});
}
set<pair<int, int> > dij;
vector<int> dp(v + 1, 0);
dp[1] = 1e9 + 1;
dij.insert({dp[1], 1});
while(!dij.empty()){
int u = dij.rbegin()->second;
dij.erase(*dij.rbegin());
for(pair<int, int> vv : adj[u]) {
int quality = min(vv.first, dp[u]);
if(quality > dp[vv.second]) {
dp[vv.second] = quality;
dij.insert({dp[vv.second], vv.second});
}
}
}
while(q--){
int x; cin >> x; cout << dp[x] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3708 KB |
Output is correct |
2 |
Correct |
25 ms |
3092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3489 ms |
124416 KB |
Output is correct |
2 |
Correct |
3445 ms |
262144 KB |
Output is correct |