이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5+5;
typedef long long ll;
ll d[MN], A[MN], B[MN], a[MN], b[MN], n, m, s, t, u, v, i, x, y, w, st[MN], cnt[MN];
queue<ll> q; vector<pair<ll,ll>> adj[MN];
int main(){
scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&s,&t,&u,&v);
for(i=1;i<=m;i++){
scanf("%lld%lld%lld",&x,&y,&w);
adj[x].push_back({y,w});
adj[y].push_back({x,w});
}
memset(a,0x3f,sizeof(a));
memset(b,0x3f,sizeof(b));
memset(d,0x3f,sizeof(d));
memset(A,0x3f,sizeof(A));
memset(B,0x3f,sizeof(B));
q.push(u); st[u]=cnt[u]=1; a[u]=0;
while(q.size()){
ll nd = q.front(); q.pop();
cnt[nd]--;
if(!st[nd]) continue;
else st[nd]=0;
for(auto v : adj[nd]){
if(a[nd]+v.second<a[v.first]){
st[v.first]=1;
a[v.first]=a[nd]+v.second;
if(!cnt[v.first]){cnt[v.first]++; q.push(v.first);}
}
}
}
memset(st,0,sizeof(st));
memset(cnt,0,sizeof(cnt));
q.push(v); st[v]=cnt[v]=1; b[v]=0;
while(q.size()){
ll nd = q.front(); q.pop();
cnt[nd]--;
if(!st[nd]) continue;
else st[nd]=0;
for(auto v : adj[nd]){
if(b[nd]+v.second<b[v.first]){
st[v.first]=1;
b[v.first]=b[nd]+v.second;
if(!cnt[v.first]){cnt[v.first]++; q.push(v.first);}
}
}
}
memset(st,0,sizeof(st));
memset(cnt,0,sizeof(cnt));
q.push(s); st[s]=cnt[s]=1; d[s]=0; A[s]=a[s]; B[s]=b[s];
while(q.size()){
ll nd = q.front(); q.pop();
cnt[nd]--;
if(!st[nd]) continue;
else st[nd]=0;
for(auto v : adj[nd]){
if(d[nd]+v.second<d[v.first]){
st[v.first]=1;
d[v.first]=d[nd]+v.second;
A[v.first]=min(a[v.first],A[nd]);
B[v.first]=min(b[v.first],B[nd]);
if(!cnt[v.first]){cnt[v.first]++; q.push(v.first);}
}
else if(d[nd]+v.second==d[v.first]&&A[nd]+B[nd]<A[v.first]+B[v.first]){
st[v.first]=1;
A[v.first]=A[nd];
B[v.first]=B[nd];
if(!cnt[v.first]){cnt[v.first]++; q.push(v.first);}
}
}
}
printf("%lld\n",min(a[v],A[t]+B[t]));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&s,&t,&u,&v);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld",&x,&y,&w);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |