다익스트라 / 플로이드
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int ans, dp1[201],dp2[201],dp3[201];
const int INF = 2e8+4;
vector<pair<int,int>> list[201];
void dijstra(int st, int n, int s[]) {
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
fill(s+1, s+n+1, INF);
pq.push({0, st});
s[st]=0;
while(!pq.empty()) {
pair<int,int> curr = pq.top();
pq.pop();
for(pair<int,int> next : list[curr.second]) {
if(s[next.second] > curr.first+next.first) {
s[next.second] = curr.first+next.first;
pq.push({s[next.second], next.second});
}
}
}
}
int solution(int n, int s, int a, int b, vector<vector<int>> fares) {
int answer = INF;
for(int i=0; i<fares.size(); i++) {
list[fares[i][0]].push_back({fares[i][2],fares[i][1]});
list[fares[i][1]].push_back({fares[i][2],fares[i][0]});
}
dijstra(s,n,dp1);
dijstra(a,n,dp2);
dijstra(b,n,dp3);
for(int d=1; d<=n; d++) {
int sum = dp1[d] + dp2[d] + dp3[d];
if(sum < answer) answer = sum;
}
return answer;
}