#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
struct edge {
int v, w;
bool operator<(const edge &other) const {
return w < other.w;
}
};
int V, E, Q;
vector< vector<edge> > adj;
vector<int> dist;
void dijkstra(int start) {
priority_queue<edge> pq;
dist.assign(V, 0);
dist[start] = INF;
pq.push({start, INF});
while (pq.size()) {
edge cur = pq.top();
pq.pop();
for (edge e: adj[cur.v]) {
int newdist = min(cur.w, e.w);
if (newdist > dist[e.v]) {
dist[e.v] = newdist;
pq.push({e.v, newdist});
}
}
}
}
signed main() {
cin >> V >> E >> Q;
adj.resize(V);
for (int e = 0; e < E; ++e) {
int u, v, q;
cin >> u >> v >> q;
adj[u-1].push_back({v-1, q});
adj[v-1].push_back({u-1, q});
}
dijkstra(0);
for (int q = 0; q < Q; ++q) {
int X;
cin >> X;
cout << dist[X-1] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
552 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
3548 KB |
Output is correct |
2 |
Correct |
104 ms |
3120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3507 ms |
56908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |