Submission #970343

#TimeUsernameProblemLanguageResultExecution timeMemory
970343VMaksimoski008Sightseeing (NOI14_sightseeing)C++17
25 / 25
3036 ms262144 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...