이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define ar array<int, 3>
bool ckmin(int& a, int b){return b < a ? a = b, 1 : 0;}
bool ckmax(int& a, int b){return b > a ? a = b, 1 : 0;}
const int N = 2e5 + 5, mod = 1e9 + 7, INF = 1e18;
vector<ar> a[N];
vector<int> e[N];
int dp[N], dp2[N], dp3[N], val[N], vis[N], dp4[N];
map<pii, int> mp, mp2;
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v;
priority_queue<pii, vector<pii>, greater<pii>> pq;
for(int i = 1; i <= m; i++) {
int x, y, z; cin >> x >> y >> z;
a[x].pb({y, z, i});
a[y].pb({x, z, i});
}
for(int i = 1; i <= n; i++) dp[i] = dp3[i] = dp2[i] = dp4[i] = INF ;
pq.push({0, s});
dp[s] = 0;
while(!pq.empty()) {
pii p = pq.top(); pq.pop();
if(p.fi > dp[p.se]) continue;
for(auto i : a[p.se]) {
if(dp[i[0]] > p.fi + i[1]) {
dp[i[0]] = p.fi + i[1];
pq.push({dp[i[0]], i[0]});
}
}
}
int mn = dp[t];
queue<int> q;
q.push(t);
while(!q.empty()) {
int p = q.front(); q.pop();
for(auto i : a[p]) {
if(dp[i[0]] + i[1] == dp[p]) {
if(!val[i[2]]) {
mp[{i[0], p}] = 1;
mp2[{p, i[0]}] = 1;
val[i[2]] = 1;
q.push(i[0]);
}
}
}
}
priority_queue<ar, vector<ar>, greater<ar>> pqq;
pqq.push({0, u, -1});
dp2[u] = 0;
while(!pqq.empty()) {
ar p = pqq.top(); pqq.pop();
if(p[0] > dp2[p[1]]) continue;
for(auto i : a[p[1]]) {
int t = (p[2] && mp[{p[1], i[0]}]);
if(!t && p[2] == -1) t = -1;
if(dp2[i[0]] > p[0] + (t == 1 ? 0 : i[1])) {
dp2[i[0]] = p[0] + (t == 1 ? 0 : i[1]);
pqq.push({dp2[i[0]], i[0], t});
}
}
}
pqq.push({0, u, -1});
dp4[u] = 0;
while(!pqq.empty()) {
ar p = pqq.top(); pqq.pop();
if(p[0] > dp4[p[1]]) continue;
for(auto i : a[p[1]]) {
int t = (p[2] && mp2[{p[1], i[0]}]);
if(!t && p[2] == -1) t = -1;
if(dp4[i[0]] > p[0] + (t == 1 ? 0 : i[1])) {
dp4[i[0]] = p[0] + (t == 1 ? 0 : i[1]);
pqq.push({dp4[i[0]], i[0], t});
}
}
}
pq.push({0, v});
dp3[v] = 0;
while(!pq.empty()) {
pii p = pq.top(); pq.pop();
if(p.fi > dp3[p.se]) continue;
for(auto i : a[p.se]) {
if(dp3[i[0]] > p.fi + i[1]) {
dp3[i[0]] = p.fi + i[1];
pq.push({dp3[i[0]], i[0]});
}
}
}
int ans = INF;
for(int i = 1; i <= n; i++) {
ans = min(ans, dp3[i] + min(dp2[i], dp4[i]));
}
cout << ans << endl ;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:39:9: warning: unused variable 'mn' [-Wunused-variable]
39 | int mn = dp[t];
| ^~
# | 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... |