-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11404.cpp
More file actions
54 lines (48 loc) · 1.14 KB
/
11404.cpp
File metadata and controls
54 lines (48 loc) · 1.14 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
#include <bits/stdc++.h>
#define SETTING ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define MAX_INT 100000000
using namespace std ;
int Floyd[101][101] ;
int N, M ;
void InputSetting()
{
//Initialize the value in to MAX
fill(&Floyd[0][0], &Floyd[100][101], MAX_INT);
int s_point, d_point, weight ;
cin >> N >> M ;
//Set itself zero
for(int i = 1 ; i <= N ; i++)
Floyd[i][i] = 0 ;
//Connect the line
for(int i = 0 ; i < M ; i++)
{
cin >> s_point >> d_point >> weight ;
Floyd[s_point][d_point] = min(weight, Floyd[s_point][d_point]) ;
}
}
void FloydWarshall()
{
for(int k = 1 ; k <= N ; k++)
for(int i = 1 ; i <= N ; i++)
for(int j = 1 ; j <= N ; j++)
Floyd[i][j] = min(Floyd[i][j], Floyd[i][k] + Floyd[k][j]) ;
}
void PrintAnswer()
{
for(int i = 1 ; i <= N ; i++)
{
for(int j = 1 ; j <= N ; j++)
{
Floyd[i][j] == MAX_INT ? cout << "0 " : cout << Floyd[i][j] << " " ;
}
cout << endl ;
}
}
int main()
{
SETTING ;
InputSetting() ;
FloydWarshall() ;
PrintAnswer() ;
}