이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;
int n, m, s, t, u, v;
vector<vector<pair<int, int>>>adj;
void dijkstras(int start, int end, vector<long long> &dist, vector<bool> &path){
priority_queue<pair<long long, int>> q;
vector<bool> visited(n+1);
vector<vector<int>>parents(n+1);
dist[start] = 0;
q.push({0,start});
while(!q.empty()){
int node = q.top().second;
q.pop();
if(visited[node])
continue;
visited[node] = true;
for(auto edge : adj[node]){
int next = edge.first;
int weight = edge.second;
if(dist[node] + weight < dist[next]){
dist[next] = dist[node] + weight;
path[next] = true;
q.push({-dist[next],next});
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> s >> t >> u >> v;
adj = vector<vector<pair<int, int>>>(n+1);
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});
}
vector<long long> distS(n+1, LONG_LONG_MAX), distV(n+1, LONG_LONG_MAX);
vector<bool> pathS(n+1), pathV(n+1);
dijkstras(s,t,distS,pathS);
dijkstras(v,u,distV,pathV);
long long ans = distV[u];
for(int i = 1; i <= n; i++){
if(pathS[i])
ans = min(ans, distV[i]);
}
cout << ans << '\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... |