이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
const ll INF = 1e18;
vector<pii> adj[N];
ll d[N][3], ds[N], dt[N];
int n, m, s, t, u, v;
bool check(int x, int y, int w, bool why){
if(why)
return ds[y]+w+dt[x]==ds[t];
else
return ds[x]+w+dt[y]==ds[t];
}
void dij(int s){
for(int i = 1; i <= n; ++i)
dt[i] = INF;
priority_queue<pli, vector<pli>, greater<pli>> pq;
dt[s] = 0;
pq.push({0, s});
while(!pq.empty()){
int x = pq.top().ss;
ll val = pq.top().ff;
pq.pop();
if(dt[x] != val)
continue;
tr(it, adj[x]){
int a = it->ff, w = it->ss;
if(umin(dt[a], dt[x]+w))
pq.push({dt[a], a});
}
}
}
ll solve(bool why){
for(int i = 1; i <= n; ++i)
for(int j = 0; j < 3; ++j)
d[i][j] = INF;
using node = tuple<ll, int, int>;
// dttance, node, type
priority_queue<node, vector<node>, greater<node>> pq;
d[u][0] = 0;
pq.push({0, u, 0});
while(!pq.empty()){
int x, type;
ll val;
tie(val, x, type) = pq.top();
pq.pop();
if(d[x][type] != val)
continue;
if(type<2 and umin(d[x][type+1], d[x][type]))
pq.push({d[x][type+1], x, type+1});
tr(it, adj[x]){
int y = it->ff, w = it->ss;
if(type==0 and umin(d[y][0], d[x][0]+w))
pq.push({d[y][0], y, 0});
else if(type==1 and check(x, y, w, why) and umin(d[y][1], d[x][1]))
pq.push({d[y][1], y, 1});
else if(type == 2 and umin(d[y][2], d[x][2]+w))
pq.push({d[y][2], y, 2});
}
}
return d[v][2];
}
int main(){
scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v);
for(int i = 1; i <= m; ++i){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
adj[a].pb({b, c});
adj[b].pb({a, c});
}
dij(s);
for(int i = 1; i <= n; ++i)
ds[i] = dt[i];
dij(t);
printf("%lld\n", min(solve(0), solve(1)));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | 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... |