-
Notifications
You must be signed in to change notification settings - Fork 0
/
crosscountry.cpp
37 lines (37 loc) · 945 Bytes
/
crosscountry.cpp
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
// GitHub: EntityPlantt/Kattis
#include <iostream>
#include <string.h>
using namespace std;
int main() {
size_t n, s, t;
cin >> n >> s >> t;
size_t graph[n][n], path[n];
bool visited[n];
memset(visited, false, sizeof(visited));
for (size_t i = 0; i < n; i++) {
path[i] = -1;
for (size_t j = 0; j < n; j++) {
cin >> graph[i][j];
}
}
path[s] = 0;
while (true) {
size_t now = n, nowSize = -1;
for (size_t i = 0; i < n; i++) {
if (!visited[i] && nowSize > path[i]) {
now = i;
nowSize = path[i];
}
}
if (now == n) {
break;
}
visited[now] = true;
for (size_t i = 0; i < n; i++) {
if (!visited[i] && path[now] + graph[now][i] < path[i]) {
path[i] = graph[now][i] + path[now];
}
}
}
cout << path[t];
}