#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")
int32_t main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<pii> graph[n+1];
for(int i=0; i<m; i++) {
int a, b, w;
cin >> a >> b >> w;
graph[a].push_back({ b, w });
graph[b].push_back({ a, w });
}
vector<ll> dist(n+1, 1e18);
vector<bool> vis(n+1);
priority_queue<pll, vector<pll>, greater<pll> > pq;
dist[1] = -1e18;
pq.push({ dist[1], 1 });
while(!pq.empty()) {
auto [d, u] = pq.top();
pq.pop();
if(vis[u]) continue;
vis[u] = 1;
for(auto &[v, w] : graph[u]) {
ll newD = max(d, -(ll)w);
if(newD < dist[v]) {
dist[v] = newD;
pq.push({ dist[v], v });
}
}
}
while(q--) {
int x;
cin >> x;
cout << -dist[x] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3672 KB |
Output is correct |
2 |
Correct |
17 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1956 ms |
114284 KB |
Output is correct |
2 |
Correct |
3036 ms |
262144 KB |
Output is correct |