이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
if (cur.w < dist[cur.v])
continue;
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() {
ios::sync_with_stdio(0);
cin.tie(0);
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;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |