이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,a,b,c,d;
vector<pair<ll,int>> adj[100001];
vector<ll> dijkstra(int v){
vector<ll> dist(n+1,-1);
priority_queue<pair<ll,int>,vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
pq.push({0,v});
while(!pq.empty()){
auto [cost,w] = pq.top();
pq.pop();
if(dist[w]!=-1)continue;
dist[w]=cost;
for(auto [dist,e] : adj[w]){
pq.push({dist+cost,e});
}
}
return dist;
}
int main(){
// cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> a >> b >> c >> d;
for(int i=0;i<m;i++){
int x,y,cost; cin >> x >> y >> cost;
adj[x].push_back({cost,y});
adj[y].push_back({cost,x});
}
vector<ll> path1 = dijkstra(a),path2 = dijkstra(b),sus1=dijkstra(c),sus2=dijkstra(d);
vector<ll> dp(n+1,LLONG_MAX/4),dp1(n+1,LLONG_MAX/4),dp2(n+1,LLONG_MAX/4);
// vector<pair<ll,ll>> dp1(n+1,{LLONG_MAX,LLONG_MAX}),dp2(n+1,{LLONG_MAX,LLONG_MAX});
vector<pair<ll,int>> jan;
for(int i=1;i<=n;i++){
if(path1[i]+path2[i]==path1[b])jan.push_back({path1[i],i});
}
dp[a]=sus1[a]+sus2[a];
dp1[a]=sus1[a];
dp2[a]=sus2[a];
sort(jan.begin(),jan.end());
for(int i=0;i<jan.size();i++){
int v = jan[i].second;
for(auto [cost, w] : adj[v]){
if(path1[v]+path2[v]==path1[b]&&path1[w]<path1[v]){
dp1[v]=min(dp1[w],sus1[v]);
dp2[v]=min(dp2[w],sus2[v]);
dp[v]=min(dp[v],dp[w]);
dp[v]=min(min(sus1[v]+sus2[v],dp[v]),min(dp1[v]+sus2[v],sus1[v]+dp2[v]));
}
}
// cout << v << ": " << dp[v] << ' ' << dp1[v] << ' ' << dp2[v] << '\n';
}
cout << min(dp[b],sus1[d]);
// cout << '\n';
// for(int i = 0;i<jan.size();i++)cout << jan[i].first << ' ' << jan[i].second << '\n';
// cout << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=0;i<jan.size();i++){
| ~^~~~~~~~~~~
# | 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... |