이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;
void dfs(int s, vector<vector<int>> &adj, vector<bool> &on_sp, vector<bool> &visited){
if(visited[s])
return;
visited[s] = true;
on_sp[s] = true;
for(auto u : adj[s])
dfs(u,adj,on_sp,visited);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("in.txt","r",stdin);
int n, m, s, t, u, v;
cin >> n >> m >> s >> t >> u >> v;
vector<vector<pair<int, int>>> adj(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});
}
priority_queue<pair<long long, int>> q;
vector<long long>dist(n+1,LONG_LONG_MAX);
vector<bool> visited(n+1);
vector<vector<int>>parents(n+1);
vector<bool> on_sp(n+1);
q.push({0,s});
dist[s] = 0;
while(!q.empty()){
int node = q.top().second;
long long dist_node = -q.top().first;
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;
parents[next].clear();
parents[next].push_back(node);
q.push({-dist[next],next});
}else if(dist[node] + weight == dist[next]){
parents[next].push_back(node);
}
}
}
fill(visited.begin(), visited.end(), false);
dfs(t,parents,on_sp,visited);
fill(visited.begin(), visited.end(), false);
vector<long long> distV(n+1, LONG_LONG_MAX);
q.push({0,v});
distV[v] = 0;
long long ans = LONG_LONG_MAX;
while(!q.empty()){
int node = q.top().second;
int dist_node = -q.top().first;
q.pop();
if(visited[node])
continue;
visited[node] = true;
for(auto edge : adj[node]){
int next = edge.first;
int weight = edge.second;
if(distV[node] + weight < distV[next]){
distV[next] = distV[node] + weight;
if(on_sp[next])
ans = min(ans, distV[next]);
q.push({-distV[next],next});
}
}
}
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:37:19: warning: unused variable 'dist_node' [-Wunused-variable]
37 | long long dist_node = -q.top().first;
| ^~~~~~~~~
commuter_pass.cpp:65:13: warning: unused variable 'dist_node' [-Wunused-variable]
65 | int dist_node = -q.top().first;
| ^~~~~~~~~
# | 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... |