제출 #970341

#제출 시각아이디문제언어결과실행 시간메모리
970341VMaksimoski008관광 (NOI14_sightseeing)C++17
15 / 25
3548 ms170860 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int32_t main() {
    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;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...