이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define fi first
#define se second
#define pb emplace_back
#define ii pair<ll, int>
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define sz(s) (int)((s).size())
#define all(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define F0R(i, b) for (int i = 0, _b = (b); i < _b; ++i)
#define FORd(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define F0Rd(i, b) for (int i = (b)-1; i >= 0; i--)
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
template<typename T1,typename T2> bool ckmax(T1 &x,const T2 &y){if(x<y){x=y; return 1;} return 0;}
template<typename T1,typename T2> bool ckmin(T1 &x,const T2 &y){if(y<x){x=y; return 1;} return 0;}
const int MOD = (int)1e9 + 7;
const int mod = 998244353;
const int N = 2e5 + 10, M = 18;
const long long INF = (long long)4e18 + 11;
/*
/\_/\
(= ._.)
/ >? \>$
*/
int n, m, s, t, u, v;
long long res;
long long d1[N], d2[N], d[N], F[N][2];
vector<ii> adj[N];
priority_queue<ii, vector<ii>, greater<ii>> pq;
void dijkstra1(int s, long long d[]){
FOR(i, 1, n) d[i] = INF;
d[s] = 0;
while(sz(pq)) pq.pop();
pq.push({d[s], s});
while(sz(pq)){
int u = pq.top().se;
long long cost = pq.top().fi;
pq.pop();
if(d[u] < cost) continue;
for(auto [v, w] : adj[u]) if(ckmin(d[v], d[u] + w)) pq.push({d[v], v});
}
}
void dijkstra2(int s, int t){
FOR(i, 1, n){
d[i] = INF;
F[i][0] = F[i][1] = INF;
}
d[s] = 0;
while(sz(pq)) pq.pop();
pq.push({d[s], s});
F[s][0] = d1[s];
F[s][1] = d2[s];
while(sz(pq)){
int u = pq.top().se;
long long cost = pq.top().fi;
pq.pop();
if(d[u] < cost) continue;
for(auto [v, w] : adj[u]){
if(ckmin(d[v], d[u] + w)){
pq.push({d[v], v});
F[v][0] = min(F[u][0], d1[v]);
F[v][1] = min(F[u][1], d2[v]);
}
else if(d[v] == d[u] + w && min(F[u][0], d1[v]) + min(F[u][1], d2[v]) < F[v][0] + F[v][1]){
F[v][0] = min(F[u][0], d1[v]);
F[v][1] = min(F[u][1], d2[v]);
}
}
}
res = min(res, F[t][0] + F[t][1]);
}
void sol(void){
cin >> n >> m >> s >> t >> u >> v;
FOR(i, 1, m){
int u, v, w; cin >> u >> v >> w;
adj[u].pb(v,w);
adj[v].pb(u,w);
}
dijkstra1(u, d1); dijkstra1(v, d2);
res = d1[v];
dijkstra2(s, t);
dijkstra2(t, s);
cout << res << '\n';
}
signed main(void){
#define TASK "nhap"
if(fopen(TASK".inp", "r")){
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int t = 1;
// cin >> t;
while(t--) sol();
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void dijkstra1(int, long long int*)':
commuter_pass.cpp:49:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
49 | for(auto [v, w] : adj[u]) if(ckmin(d[v], d[u] + w)) pq.push({d[v], v});
| ^
commuter_pass.cpp: In function 'void dijkstra2(int, int)':
commuter_pass.cpp:68:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
68 | for(auto [v, w] : adj[u]){
| ^
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
101 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | 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... |