이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long, long long>
const ll inf = 1e18;
const int maxn = 100005;
// const int maxn = 50;
int n, m, s, t, u, v;
pll dist[maxn]; // <parent, dist>
priority_queue<pll, vector<pll>, greater<pll>> pq;
map<int, int> adj[maxn];
int main() {
for (int i = 0; i < maxn; i++) {
dist[i] = {-1, inf};
}
cin >> n >> m >> s >> t >> u >> v;
for (int i = 0; i < m; i++) {
ll a, b, c;
cin >> a >> b >> c;
adj[a][b] = c;
adj[b][a] = c;
}
pq.push({0, s});
dist[s] = {s, 0};
while (!pq.empty()) {
auto [currdist, idx] = pq.top();
for (auto [b, c] : adj[idx]) {
if (currdist + c < dist[b].second) { // potential?
dist[b] = {idx, currdist + c};
pq.push({currdist+c, b});
}
}
pq.pop();
}
int x = t;
while (x != s) {
adj[x][dist[x].first] = 0;
adj[dist[x].first][x] = 0;
x = dist[x].first;
}
for (int i = 0; i < maxn; i++) {
dist[i] = {-1, inf};
}
pq.push({0, u});
dist[u] = {u, 0};
while (!pq.empty()) {
auto [currdist, idx] = pq.top();
for (auto [b, c] : adj[idx]) {
if (currdist + c < dist[b].second) { // potential?
dist[b] = {idx, currdist + c};
pq.push({currdist+c, b});
}
}
pq.pop();
}
cout << dist[v].second << endl;
return 0;
}
| # | 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... |