이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
#define int long long
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int n, m;cin >> n >> m;
int s, t;cin >> s >> t; --s;--t;
int u, v;cin >> u >> v; --u;--v;
vector<array<int, 3>> fake_edg(m);
vector<vector<pair<int, int>>> fake_adj(n);
for(auto &[a, b, c] : fake_edg){
cin >> a >> b >> c;
--a;--b;
fake_adj[a].push_back({b, c});
fake_adj[b].push_back({a, c});
}
set<pair<int,int>> selected_edges;/*{{{*/
priority_queue<pair<int,int>> pq;
vector<int> fake_dist(n, 1e18);
fake_dist[s] = 0;
pq.push({-fake_dist[s], s});
while(!pq.empty()){
auto [dd, x] = pq.top();
dd = -dd;
pq.pop();
if(fake_dist[x] != dd)continue;
for(auto [e, w] : fake_adj[x]){
if(fake_dist[e] > fake_dist[x] + w){
fake_dist[e] = fake_dist[x] + w;
pq.push({-fake_dist[e], e});
}
}
}
pq.push({-fake_dist[s], s});
vector<vector<pair<int,int>>> temp_adj(n);
while(!pq.empty()){
auto [dd, x] = pq.top();
dd = -dd;
pq.pop();
for(auto [e, w] : fake_adj[x]){
if(fake_dist[e] == fake_dist[x] + w){
temp_adj[e].push_back({x, w});
pq.push({-fake_dist[e], e});
}
}
}
fill(fake_dist.begin(), fake_dist.end(), 1e18);
fake_dist[t] = 0;
pq.push({-fake_dist[t], t});
while(!pq.empty()){
auto [dd, x] = pq.top();
dd = -dd;
pq.pop();
for(auto [e, w] : temp_adj[x]){
if(fake_dist[e] > fake_dist[x] + w){
fake_dist[e] = fake_dist[x] + w;
pq.push({-fake_dist[e], e});
}
}
}
pq.push({-fake_dist[t], t});
vector<int> lev(n, -1);
lev[t] = 0;
while(!pq.empty()){
auto [dd, x] = pq.top();
dd = -dd;
pq.pop();
for(auto [e, w] : temp_adj[x]){
if(fake_dist[e] == fake_dist[x] + w){
selected_edges.insert({min(e, x), max(e, x)});
lev[e] = lev[x] + 1;
pq.push({-fake_dist[e], e});
}
}
}/*}}}*/
// deb(selected_edges);
// deb(lev);
// vector<vector<pair<int,int>>> adj(n);
// for(auto [a, b, c] : fake_edg){
// if(a > b)swap(a, b);
// if(selected_edges.find({a, b}) != selected_edges.end()){
// if(lev[a] < lev[b]){
// deb(a, b);
// adj[a].push_back({b, 0});
// adj[b].push_back({a, c});
// }
// else{
// deb(b, a);
// adj[b].push_back({a, 0});
// adj[a].push_back({b, c});
// }
// }
// else{
// adj[a].push_back({b, c});
// adj[b].push_back({a, c});
// }
// }
// vector<int> dist(n, 1e18);
// dist[u] = 0;
// pq.push({-dist[u], u});
// while(!pq.empty()){
// auto [dd, x] = pq.top();
// pq.pop();
// dd = -dd;
// if(dist[x] != dd)continue;
// for(auto [e, w] : adj[x]){
// if(dist[e] > dist[x] + w){
// dist[e] = dist[x] + w;
// pq.push({-dist[e], e});
// }
// }
// }
// int ans = dist[v];
// cout << ans << "\n";
// adj.clear();
// adj.resize(n);
// for(auto [a, b, c] : fake_edg){/*{{{*/
// if(a > b)swap(a, b);
// if(selected_edges.find({a, b}) != selected_edges.end()){
// if(lev[a] > lev[b]){
// deb(a, b);
// adj[a].push_back({b, 0});
// adj[b].push_back({a, c});
// }
// else{
// deb(b, a);
// adj[b].push_back({a, 0});
// adj[a].push_back({b, c});
// }
// }
// else{
// adj[a].push_back({b, c});
// adj[b].push_back({a, c});
// }
// }
// fill(dist.begin(), dist.end(), 1e18);
// dist[u] = 0;
// pq.push({-dist[u], u});
// while(!pq.empty()){
// auto [dd, x] = pq.top();
// pq.pop();
// dd = -dd;
// if(dist[x] != dd)continue;
// for(auto [e, w] : adj[x]){
// if(dist[e] > dist[x] + w){
// dist[e] = dist[x] + w;
// pq.push({-dist[e], e});
// }
// }
// }
// ans = min(ans, dist[v]);
// cout << ans << "\n";/*}}}*/
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:17:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
17 | for(auto &[a, b, c] : fake_edg){
| ^
commuter_pass.cpp:29:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | auto [dd, x] = pq.top();
| ^
commuter_pass.cpp:33:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | for(auto [e, w] : fake_adj[x]){
| ^
commuter_pass.cpp:43:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
43 | auto [dd, x] = pq.top();
| ^
commuter_pass.cpp:46:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | for(auto [e, w] : fake_adj[x]){
| ^
commuter_pass.cpp:57:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
57 | auto [dd, x] = pq.top();
| ^
commuter_pass.cpp:60:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
60 | for(auto [e, w] : temp_adj[x]){
| ^
commuter_pass.cpp:71:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
71 | auto [dd, x] = pq.top();
| ^
commuter_pass.cpp:74:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
74 | for(auto [e, w] : temp_adj[x]){
| ^
# | 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... |