Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdijkstra.cpp
More file actions
Latest commit
executable file
·59 lines (58 loc) · 1.98 KB
/
Copy pathdijkstra.cpp
File metadata and controls
executable file
·59 lines (58 loc) · 1.98 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>
#definefastioios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#defineendl'\n'
#defineintlonglongint
usingnamespacestd;
#definepii pair <int, int>
#definemii map<int, int>
#definepb push_back
#definedeb(x) cout << #x << "" << x << endl
#definedeb2(x, y) cout << #x << "" << x << "" << #y << "" << y << endl
#defineLoop(s, e, itr) for (int itr = s; itr < e; itr++)
#defineloop(n) for(int i = 0; i < n; i++)
#definevin vector<int>
#definew(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#definevec vector
#definemk_arr(n, t, s) t* n = new t[s]; loop(s) cin >> n[i];
#definemi_arr(n, s) int* n = newint[s]; loop(s) cin >> n[i];
#definearr_out(n, s) Loop(0, s, lout) cout << n[lout] << "";
#definepi(x) printf("%lld ", x);
int32_tmain(){
int dp[5][5] = {
{10000000, 10000000, 1, 4, 10000000},
{6, 10000000, 10000000, 10000000, 10000000},
{10000000, 10000000, 10000000, 10000000, 10000000},
{10000000, -1, 2, 10000000, 1},
{10000000, 4, 3, 10000000, 10000000}
};
int path[5][5] = {
{-1, -1, 0, 0, -1},
{ 0, -1, -1, -1, -1},
{-1, -1, -1, -1, -1},
{-1, 0, 0, -1, 0},
{-1, 0, 0, -1, -1}
};
Loop(0, 5, k){
Loop(0, 5, i)
Loop(0, 5, j){
int temp = dp[i][k]+dp[k][j];
if(temp < dp[i][j]) {
dp[i][j] = temp;
path[i][j] = k+1;
}
}
deb(k+1);
cout << "dp\n";
Loop(0, 5, i) {
Loop(0, 5, j) if(dp[i][j] == 10000000) cout << "- "; else cout << dp[i][j] << "";
cout << endl;
}
cout << endl;
cout << "path\n";
Loop(0, 5, i) {
Loop(0, 5, j) if(path[i][j] == -1) cout << "- "; else cout << path[i][j] << "";
cout << endl;
}
cout << endl << endl << endl;
}
}