Submission #124650

# Submission time Handle Problem Language Result Execution time Memory
124650 2019-07-03T16:25:42 Z Touubs Sightseeing (NOI14_sightseeing) C++17
15 / 25
3434 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
 
 
signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);

  int v, e, q;
  cin >> v >> e >> q;
  vector<vector<pair<int, int>>> graph(v+1);
 
  for (int i = 0; i < e; i++) {
    int a, b, qual;
    cin >> a >> b >> qual;
    graph[a].emplace_back(qual, b);
    graph[b].emplace_back(qual, a);
  }
 
  priority_queue<pair<int, int>> queue;
  queue.push(make_pair(1000000, 1));
  vector<bool> visited(v + 1);
  vector<int> optimum(v + 1);
 
  while (!queue.empty()) {
    pair<int, int> pos = queue.top();
    queue.pop();
 
    if (visited[pos.second]) continue;
    visited[pos.second] = true;
    
    optimum[pos.second] = pos.first;
 
    for (pair<int, int> adj : graph[pos.second]) {
      queue.push(make_pair(min(pos.first, adj.first), adj.second));
    }
  }
 
  for (int i = 0; i < q; i++) {
    int query;
    cin >> query;
    cout << optimum[query] << "\n";
  }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 888 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 5236 KB Output is correct
2 Correct 43 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3434 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -