-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path030801.cpp
More file actions
42 lines (32 loc) · 924 Bytes
/
Copy path030801.cpp
File metadata and controls
42 lines (32 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <string>
#include <vector>
using namespace std;
#define INF 2100000000
int dist[201][201];
int solution(int n, int s, int a, int b, vector<vector<int>> fares) {
int answer = 0;
for(int i=1; i<= n; i++){
for(int j=1; j<=n; j++){
dist[i][j] = INF;
}
dist[i][i] = 0;
}
for(vector<int> fare: fares){
dist[fare[0]][fare[1]]=fare[2];
dist[fare[1]][fare[0]]=fare[2];
}
for(int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if((long long)dist[i][j] > (long long)dist[i][k] + dist[k][j]){
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
answer = dist[s][a] + dist[s][b];
for(int i=1; i<=n; i++){
answer = min(answer, dist[s][i] + dist[i][a] + dist[i][b]);
}
return answer;
}