이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(v) v.begin(), v.end();
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int N = 2e5 + 3;
const ll INF = 1e18;
int n, m, a, b, c, d;
vector<ii> adj[N];
bool vst[N];
ll best;
ll dp_one[N], dp_two[N];
vector<ll> one, two, three, four;
bool in_shortest_path(int u, int v, int w) {
return one[u] + w + two[v] == one[b];
}
void prepare() {
}
void input() {
cin >> n >> m >> a >> b >> c >> d;
for(int i = 1; i <= m; i++) {
int u, v, w; cin >> u >> v >> w;
adj[u].push_back(ii(v, w));
adj[v].push_back(ii(u, w));
}
}
void dijkstra(int node, vector<ll> &d) {
d.resize(n + 1, INF);
priority_queue<li, vector<li>, greater<li>> pq;
d[node] = 0; pq.push(li(0, node));
while(!pq.empty()) {
ll cost; int u; tie(cost, u) = pq.top(); pq.pop();
if(cost > d[u]) continue;
for(int i = 0; i < (int)adj[u].size(); i++) {
int v, w; tie(v, w) = adj[u][i];
if(d[v] > d[u] + w) {
d[v] = d[u] + w;
pq.push(li(d[v], v));
}
}
}
}
void dfs(int u) {
vst[u] = true;
dp_one[u] = dp_two[u] = INF;
for(int i = 0; i < (int)adj[u].size(); i++) {
int v, w; tie(v, w) = adj[u][i];
if(!in_shortest_path(u, v, w)) continue;
if(!vst[v]) dfs(v);
dp_one[u] = min(dp_one[u], dp_one[v]);
dp_two[u] = min(dp_two[u], dp_two[v]);
}
best = min(best, three[u] + dp_two[u]);
best = min(best, dp_one[u] + four[u]);
dp_one[u] = min(dp_one[u], three[u]);
dp_two[u] = min(dp_two[u], four[u]);
}
void process() {
dijkstra(a, one);
dijkstra(b, two);
dijkstra(c, three);
dijkstra(d, four);
best = three[d];
dfs(a);
cout << best << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#define task "BUS"
if(fopen(task".INP", "r")) {
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}else {
// freopen(task".in", "r", stdin);
// freopen(task".out", "w", stdout);
}
prepare();
int testcase = 1; // cin >> testcase;
for(int i = 1; i <= testcase; i++) {
input();
process();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | 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... |