이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
void World_Final();
void Solve();
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if (fopen(taskname".in", "r")) {
freopen(taskname".in", "r", stdin);
freopen(taskname".out", "w", stdout);
}
World_Final();
}
void World_Final(){
int Tests = 1;
//cin >> Tests;
for (int i = 1; i <= Tests; i ++) {
//cout << i << "\n";
Solve();
}
}
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 10;
const int64_t INF = 1e18;
int N, M, S, T, U, V; vector<pair<int, int>> G[MAXN]; int64_t D[MAXN][2], F[MAXN][3];
pair<int64_t, int> Trace[MAXN];
void Dijkstra(int START, int t){
for (int i = 1; i <= N; i ++) D[i][t] = INF; D[START][t] = 0;
priority_queue<pair<int64_t, int>> pq; pq.push(make_pair(0, START));
while (!pq.empty()) {
int64_t d; int u; tie(d, u) = pq.top(); pq.pop();
if (-d != D[u][t]) continue;
for (auto [v, w] : G[u]) {
if (D[v][t] > D[u][t] + w) {
D[v][t] = D[u][t] + w;
pq.push(make_pair(-D[v][t], v));
}
}
}
}
void Solve(){
cin >> N >> M >> S >> T >> U >> V;
for (int i = 1; i <= M; i ++) {
int u, v, w; cin >> u >> v >> w;
G[u].push_back(make_pair(v, w));
G[v].push_back(make_pair(u, w));
} Dijkstra(S, 0); Dijkstra(T, 1);
memset(F, 0x3f3f, sizeof(F));
F[U][0] = 0;
priority_queue<pair<int64_t, pair<int, int>>> pq; pq.push(make_pair(0, make_pair(U, 0)));
while (!pq.empty()) {
int64_t d = pq.top().first;
int u, t; tie(u, t) = pq.top().second;
pq.pop();
if (-d != F[u][t]) continue;
for (auto [v, w] : G[u]) {
if (t == 0) {
if (F[v][0] > F[u][0] + w) {
F[v][0] = F[u][0] + w;
pq.push(make_pair(-F[v][t], make_pair(v, t)));
} if (F[v][1] > F[u][0]) {
int64_t tot = Trace[u].first + w;
int64_t minDist = min(D[u][0] + tot + D[v][1], D[u][1] + tot + D[v][0]);
if (minDist == D[T][0]) {
F[v][1] = F[u][0];
Trace[v] = make_pair(tot, u);
//cout << u << " " << v << " " << F[v][1] << " " << F[u][0] << "\n";
//cout << u << " " << v << " " << w << "\n";
pq.push(make_pair(-F[v][1], make_pair(v, 1)));
}
}
} else if (t == 1) {
if (F[v][1] > F[u][1]) {
int64_t tot = Trace[u].first + w;
int st = Trace[u].second;
int64_t minDist = min(D[st][0] + tot + D[v][1], D[st][1] + tot + D[v][0]);
if (minDist == D[T][0]) {
F[v][1] = F[u][1];
Trace[v] = make_pair(tot, st);
//cout << u << " " << v << " " << w << "\n";
pq.push(make_pair(-F[v][1], make_pair(v, 1)));
}
} if (F[v][2] > F[u][1] + w) {
F[v][2] = F[u][1] + w;
pq.push(make_pair(-F[v][2], make_pair(v, 2)));
}
} else if (t == 2) {
if (F[v][2] > F[u][2] + w) {
F[v][2] = F[u][2] + w;
pq.push(make_pair(-F[v][2], make_pair(v, 2)));
}
}
}
}
//cout << F[V][0] << " " << F[V][1] << " " << F[V][2] << "\n";
cout << min({F[V][0], F[V][1], F[V][2]});
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void Dijkstra(int, int)':
commuter_pass.cpp:32:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
32 | for (int i = 1; i <= N; i ++) D[i][t] = INF; D[START][t] = 0;
| ^~~
commuter_pass.cpp:32:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
32 | for (int i = 1; i <= N; i ++) D[i][t] = INF; D[START][t] = 0;
| ^
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen(taskname".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen(taskname".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... |