이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MX 100100
#define ll long long
#define x first
#define y second
int N, M, S, T, U, V;
ll dis[3][MX], best[4][MX];
bool vis[MX];
vector<pair<int, int>> adj[MX];
vector<int> par[MX], nxt[MX], prv[MX], v;
void dij(int s, int z) {
priority_queue<pair<ll, pair<int, int>>> q;
q.push({0, {s, 0}});
while (q.size()) {
pair<ll, pair<int, int>> cur = q.top(); q.pop();
if (!z && cur.y.y && (!vis[cur.y.x] || dis[z][cur.y.x] == -cur.x)) {
par[cur.y.x].push_back(cur.y.y);
}
if (vis[cur.y.x]) continue;
vis[cur.y.x] = 1;
dis[z][cur.y.x] = -cur.x;
for (pair<int, int> i : adj[cur.y.x]) {
q.push({cur.x-i.y, {i.x, cur.y.x}});
}
}
for (int i = 1; i <= N; i++) vis[i] = 0;
}
void dfs(int n) {
if (vis[n]) return;
vis[n] = 1;
for (int i : par[n]) {
nxt[i].push_back(n);
prv[n].push_back(i);
dfs(i);
}
v.push_back(n);
}
int main() {
scanf("%d%d%d%d%d%d", &N, &M, &S, &T, &U, &V);
for (int i = 0, A, B, C; i < M; i++) {
scanf("%d%d%d", &A, &B, &C);
adj[A].push_back({B, C});
adj[B].push_back({A, C});
}
dij(S, 0); dij(U, 1); dij(V, 2); dfs(T);
for (int _ = 0; _ < 2; _++) {
for (int i : v) {
for (int k = 2*_; k < 2; k++) {
best[k][i] = dis[(k&1)+1][i];
for (int j : prv[i]) {
best[k][i] = min(best[k][i], best[k][j]);
}
}
}
reverse(v.begin(), v.end());
}
ll ans = dis[1][V];
for (int i = 1; i <= N; i++) {
ans = min({ans, best[0][i]+best[3][i], best[1][i]+best[2][i]});
}
printf("%lld\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d%d%d", &N, &M, &S, &T, &U, &V);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &A, &B, &C);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |