이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
const int N = 2e5 + 15;
const ll INF = 1e18;
int n, m;
int U, V, S, T;
vector<pair<int, ll>> g[N];
// U: 1, V: 2, S: 3, T: 4
vector<ll> dist[5];
vector<int> adj[N];
ll ans = 0;
bool visted[N];
void dijk(vector<ll>& dist, int root){
dist[root] = 0;
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
pq.push({0,root});
while(!pq.empty()){
ll wu; int u; tie(wu,u) = pq.top(); pq.pop();
if(wu > dist[u]) continue;
for(auto [v, wv] : g[u]){
if(dist[v] > dist[u] + wv){
dist[v] = dist[u] + wv;
pq.push({dist[v], v});
}
}
}
}
void build(int u){
visted[u] = true;
for(auto [v, wv] : g[u]){
if(dist[1][u] + wv + dist[2][v] == dist[1][V]){
adj[u].push_back(v);
if(!visted[v]) build(v);
}
}
}
// best[i][1] = max dist[i] -> s | best[i][2] = max dist[i] -> t
ll best[N][3];
void dfs(int u){
best[u][1] = dist[3][u];
best[u][2] = dist[4][u];
for(int v : adj[u]){
dfs(v);
best[u][1] = min(best[u][1], best[v][1]);
best[u][2] = min(best[u][2], best[v][2]);
}
ans = min(ans, dist[3][u] + best[u][2]);
ans = min(ans, dist[4][u] + best[u][1]);
}
void solve(){
cin >> n >> m >> U >> V >> S >> T;
for(int i = 1; i <= m; i++){
int u, v, w; cin >> u >> v >> w;
g[u].push_back({v,w});
g[v].push_back({u,w});
}
for(int i = 1; i <= 4; i++) dist[i].resize(n+1, INF);
dijk(dist[1], U);
dijk(dist[2], V);
dijk(dist[3], S);
dijk(dist[4], T);
build(U);
ans = dist[3][T];
dfs(U);
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "bus"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |