-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParty.cpp
More file actions
47 lines (41 loc) · 796 Bytes
/
Copy pathParty.cpp
File metadata and controls
47 lines (41 loc) · 796 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
43
44
45
46
47
// Baekjoon 1238
// Floyd-Warshall Algorithm
#include <iostream>
#include <array>
#include <algorithm>
using namespace std;
const int INF{ 100001 };
int N, M, X, s, e, t;
array<array<int, 1004>, 1004>dp;
void init() {
for (int i{ 0 }; i <= N; i++) {
for (int j{ 0 }; j <= N; j++) {
dp[i][j] = INF;
}
}
}
void floyd() {
for (int k{ 1 }; k <= N; k++) {
for (int i{ 1 }; i <= N; i++) {
for (int j{ 1 }; j <= N; j++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
}
int main() {
cin >> N >> M >> X;
init();
for (int i{ 1 }; i <= M; i++) {
cin >> s >> e >> t;
dp[s][e] = t;
}
floyd();
int max_t = 0;
for (int i{ 1 }; i <= N; i++) {
if (i == X) continue;
if (max_t < dp[i][X] + dp[X][i])
max_t = dp[i][X] + dp[X][i];
}
cout << max_t << endl;
}