// https://oj.uz/problem/view/NOI14_sightseeing
#include <bits/stdc++.h>
#define int int32_t
#define coutV(x) for (const auto& e: x) {cerr << e << " ";} cerr << "\n"
using namespace std;
int V, E, Q;
vector<vector<pair<int, int>>> adj;
signed main() {
#ifndef __APPLE__
cin.tie(0);
ios_base::sync_with_stdio(0);
#endif
cin >> V >> E >> Q;
adj.resize(V);
for (int i = 0; i < E; i++) {
int v1, v2, q;
cin >> v1 >> v2 >> q;
adj[v1 - 1].emplace_back(v2 - 1, q);
adj[v2 - 1].emplace_back(v1 - 1, q);
}
// Dijkstra
vector<int> visited (V, 0);
vector<bool> bVisited (V, false);
int visitedCounter = 0;
priority_queue<pair<int, int>> pq;
pq.push({INT32_MAX, 0});
while (!pq.empty() && visitedCounter < V) {
auto top = pq.top();
pq.pop();
int v = top.second;
int pathQ = top.first;
if (bVisited[v] || visited[v] > pathQ) {
continue;
}
visited[v] = pathQ;
bVisited[v] = true;
visitedCounter += 1;
for (const auto& child: adj[v]) {
int childQ = min(child.second, pathQ);
if (visited[child.first] >= childQ) continue;
visited[child.first] = childQ;
pq.push({childQ, child.first});
}
}
for (int i = 0; i < Q; i++) {
int x;
cin >> x;
cout << visited[x - 1] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
3320 KB |
Output is correct |
2 |
Correct |
36 ms |
2936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3232 ms |
102796 KB |
Output is correct |
2 |
Execution timed out |
3554 ms |
133908 KB |
Time limit exceeded |