이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
#define pii pair<int,int>
using namespace std;
const int N=2e5+5,mod=1e9+7,Inf=1e15;
int t,dist[5][N],a[5],ans[N],n,m,Ans;
vector<pair<int,int> > ds,V[N];
priority_queue<pii,vector<pii>,greater<pii> >q;
string s;
void go(){
for(int i=1;i<=n;i++){
ans[i] = Inf;
}
ans[a[2]] = 0;
for(int i=0;i<ds.size();i++){
int u = ds[i].s;
for(int j=0;j<V[u].size();j++){
if(dist[0][u]+V[u][j].s + dist[1][V[u][j].f] == dist[1][a[0]] )
ans[V[u][j].f]=min(ans[V[u][j].f],ans[u]);
ans[V[u][j].f]=min(ans[V[u][j].f],ans[u]+V[u][j].s);
}
}
Ans=min(Ans,ans[a[3]]);
}
main(){
// t=1;
cin>>n>>m;
cin>>a[0]>>a[1]>>a[2]>>a[3];
for(int i=1;i<=m;i++){
int u,v,w;
cin>>u>>v>>w;
V[u].push_back({v,w});
V[v].push_back({u,w});
}
for(int i=0;i<4;i++){
for(int j=1;j<=n;j++) dist[i][j] = Inf;
dist[i][a[i]]=0;
q.push({0,a[i]});
while(q.size()){
int d=q.top().f;
int u=q.top().s; if(i==2)ds.push_back({d,u});
q.pop();
if(dist[i][u]<d) continue;
for(int j=0;j<V[u].size();j++){
if(dist[i][V[u][j].f]>d+V[u][j].s) {
dist[i][V[u][j].f]=d+V[u][j].s;
q.push({dist[i][V[u][j].f],V[u][j].f});
}
}
}
} Ans=1e15;
go();
swap(a[2],a[3]);
go();
cout<<Ans;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void go()':
commuter_pass.cpp:17:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0;i<ds.size();i++){
| ~^~~~~~~~~~
commuter_pass.cpp:19:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int j=0;j<V[u].size();j++){
| ~^~~~~~~~~~~~
commuter_pass.cpp: At global scope:
commuter_pass.cpp:28:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
28 | main(){
| ^
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:47:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int j=0;j<V[u].size();j++){
| ~^~~~~~~~~~~~| # | 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... |