이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// https://oj.uz/problem/view/JOI18_commuter_pass
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "JOI18_commuter_pass"
void Fi(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp", "r", stdin);
freopen(PROB".out", "w", stdout);
}
}
const ll INF = 1e18;
const int N = 1e5 + 1;
bool vis[N];
int n, m;
int S, T, U, V;
using pi = pair<int, int>;
vector<pi> adj[N];
ll du[N], dv[N], ds[N];
ll dp[2][N], ans;
using pli = pair<ll, int>;
priority_queue<pli, vector<pli>, greater<pli>> pq;
void dijkstra1(const int &s, ll d[]){
fill(d + 1, d + n + 1, INF);
fill(vis + 1, vis + n + 1, false);
pq.emplace(0, s); d[s] = 0;
while(!pq.empty()){
auto [wu, u] = pq.top(); pq.pop();
if(wu != d[u] || vis[u]) continue;
vis[u] = true;
for(auto [wv, v]: adj[u]) if(!vis[v]){
if(d[v] > wu + wv){
d[v] = wu + wv;
pq.emplace(d[v], v);
}
}
}
}
void dijkstra2(const int &s, const int &t, ll d[]){
fill(d + 1, d + n + 1, INF);
fill(dp[0] + 1, dp[0] + n + 1, INF);
fill(dp[1] + 1, dp[1] + n + 1, INF);
fill(vis + 1, vis + n + 1, false);
pq.emplace(0, s);
d[s] = 0;
dp[0][s] = du[s];
dp[1][s] = dv[s];
while(!pq.empty()){
auto [wu, u] = pq.top(); pq.pop();
if(wu != d[u] || vis[u]) continue;
vis[u] = true;
for(auto [wv, v]: adj[u]) if(!vis[v]){
if(d[v] > wu + wv){
dp[0][v] = min(du[v], dp[0][u]);
dp[1][v] = min(dv[v], dp[1][u]);
d[v] = wu + wv;
pq.emplace(d[v], v);
} else if(d[v] == wu + wv){
if(min(du[v], dp[0][u]) + min(dv[v], dp[1][u]) < dp[0][v] + dp[1][v]){
dp[0][v] = min(du[v], dp[0][u]);
dp[1][v] = min(dv[v], dp[1][u]);
}
}
}
}
ans = min(ans, dp[0][t] + dp[1][t]);
}
int main(){
IOS;
Fi();
cin >> n >> m >> S >> T >> U >> V;
FORU(i, 1, m){
int u, v, w; cin >> u >> v >> w;
adj[u].eb(w, v);
adj[v].eb(w, u);
}
dijkstra1(U, du);
dijkstra1(V, dv);
ans = du[V];
dijkstra2(S, T, ds);
dijkstra2(T, S, ds);
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void Fi()':
commuter_pass.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(PROB".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen(PROB".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... |