이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
int n, m;
int s, t;
int u, v;
vector<vector<pair<int,int>>> edg;
bool vis[100005];
ll distS[100005];
ll distT[100005];
ll distV[100005];
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
cin >> s >> t;
cin >> u >> v;
edg.resize(n+5);
for (int i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
edg[a].push_back({b,c});
edg[b].push_back({a,c});
}
priority_queue<pair<ll,int>> q;
q.push({0,s});
for (int i = 0; i <= n; i++) distS[i] = 1e18, vis[i] = 0;
distS[s] = 0;
while (!q.empty()) {
int f = q.top().second;
q.pop();
if (vis[f]) continue;
vis[f] = 1;
for (auto &[i,j] : edg[f]) {
if (!vis[i] && distS[i] > (ll) distS[f] + j) {
distS[i] = (ll) distS[f] + j;
q.push({-distS[i], i});
}
}
}
q.push({0,t});
for (int i = 0; i <= n; i++) distT[i] = 1e18, vis[i] = 0;
distT[t] = 0;
while (!q.empty()) {
int f = q.top().second;
q.pop();
if (vis[f]) continue;
vis[f] = 1;
for (auto &[i,j] : edg[f]) {
if (!vis[i] && distT[i] > (ll) distT[f] + j) {
distT[i] = (ll) distT[f] + j;
q.push({-distT[i], i});
}
}
}
q.push({0,v});
for (int i = 0; i <= n; i++) distV[i] = 1e18, vis[i] = 0;
distV[v] = 0;
while (!q.empty()) {
int f = q.top().second;
q.pop();
if (vis[f]) continue;
vis[f] = 1;
for (auto &[i,j] : edg[f]) {
if (!vis[i] && distV[i] > (ll) distV[f] + j) {
distV[i] = (ll) distV[f] + j;
q.push({-distV[i], i});
}
}
}
ll ans = 1e18;
for (int i = 1; i <= n; i++) {
if (distS[t] == distS[i] + distT[i]) {
ans = min(ans, distV[i]);
}
}
cout << ans << '\n';
//cerr << "S: "; for (int i = 1; i <= n; i++) { cerr << distS[i] << " \n" [i == n]; }
//cerr << "T: "; for (int i = 1; i <= n; i++) { cerr << distT[i] << " \n" [i == n]; }
//cerr << "V: "; for (int i = 1; i <= n; i++) { cerr << distV[i] << " \n" [i == n]; }
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... |