이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tii tuple<int, int, int>
#define pii pair<int, int>
#define ff first
#define ss second
const int maxn = 1e5 + 5, INF = 0x3f3f3f3f3f3f3f3f;
vector<pii> adj[maxn];
vector<int> g[maxn];
vector<tii> edges;
int n;
vector<int> dijkstra(int ini){
priority_queue<pii, vector<pii>, greater<pii>> pq;
vector<int> dist(n+1, INF);
dist[ini] = 0;
pq.push({0, ini});
while(pq.size()){
auto[d, u] = pq.top();
pq.pop();
if(d > dist[u]) continue;
for(int v : g[u]) if(dist[u] < dist[v]){
dist[v] = dist[u];
pq.push({dist[u], v});
}
for(auto [v, w] : adj[u]) if(dist[u]+w < dist[v]){
dist[v] = dist[u] + w;
pq.push({dist[u]+w, v});
}
}
return dist;
}
int32_t main(){
int m; cin >> n >> m;
int S, T; cin >> S >> T;
int U, V; cin >> U >> V;
for(int i = 0; i < m; i++){
int a, b, c; cin >> a >> b >> c;
adj[a].push_back({b, c});
adj[b].push_back({a, c});
edges.push_back({a, b, c});
}
vector<int> distS = dijkstra(S), distT = dijkstra(T);
int minpath = distS[T];
for(auto[a, b, c] : edges) if(distS[a] < distS[b]){
if(distS[a]+c+distT[b] == minpath) g[a].push_back(b);
}
vector<int> dist1 = dijkstra(U);
int ans = dist1[V];
for(int i = 1; i <= n; i++) g[i].clear();
for(auto[a, b, c] : edges) if(distS[a] < distS[b]){
if(distS[a]+c+distT[b] == minpath) g[b].push_back(a);
}
vector<int> dist2 = dijkstra(U);
ans = min(ans, dist2[V]);
cout << ans << '\n';
}
# | 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... |