이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <climits>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, m, s, t, u, v;
cin >> n >> m >> s >> t >> u >> v;
ll w[n+1][n+1];
vector<ll> adj[n+1];
while (m--) {
ll a, b, c;
cin >> a >> b >> c;
adj[a].push_back(b);
adj[b].push_back(a);
w[a][b] = c;
w[b][a] = c;
}
ll d[n+1], p[n+1];
bool c[n+1];
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> heap;
for (ll i=1; i<=n; i++) {
d[i] = LLONG_MAX;
c[i] = false;
p[i] = -1;
}
d[s] = 0;
heap.push({0, s});
while (!heap.empty()) {
pair<ll, ll> t = heap.top();
heap.pop();
if (!c[t.second]) {
c[t.second] = true;
for (ll x : adj[t.second]) {
if (d[x] > d[t.second]+w[t.second][x]) {
d[x] = d[t.second]+w[t.second][x];
p[x] = t.second;
heap.push({d[x], x});
}
}
}
}
ll temp = t;
while (p[temp] != -1) {
w[temp][p[temp]] = 0;
w[p[temp]][temp] = 0;
temp = p[temp];
}
for (ll i=1; i<=n; i++) {
d[i] = LLONG_MAX;
c[i] = false;
p[i] = -1;
}
d[u] = 0;
heap.push({0, u});
while (!heap.empty()) {
pair<ll, ll> t = heap.top();
heap.pop();
if (!c[t.second]) {
c[t.second] = true;
for (ll x : adj[t.second]) {
if (d[x] > d[t.second]+w[t.second][x]) {
d[x] = d[t.second]+w[t.second][x];
p[x] = t.second;
heap.push({d[x], x});
}
}
}
}
cout << d[v];
}
# | 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... |