Submission #970341

# Submission time Handle Problem Language Result Execution time Memory
970341 2024-04-26T11:37:06 Z VMaksimoski008 Sightseeing (NOI14_sightseeing) C++17
15 / 25
3500 ms 170860 KB
#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 time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 628 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 4560 KB Output is correct
2 Correct 41 ms 3928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3548 ms 170860 KB Time limit exceeded
2 Halted 0 ms 0 KB -